Skip to content

Commit

Permalink
Rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed Jul 24, 2014
1 parent fdde1df commit 73131fb
Show file tree
Hide file tree
Showing 79 changed files with 1,869 additions and 1,761 deletions.
46 changes: 46 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
inherit_from: .rubocop_todo.yml

ActionFilter:
EnforcedStyle: filter

CaseIndentation:
IndentWhenRelativeTo: end

CollectionMethods:
PreferredMethods:
find: detect

EmptyLineBetweenDefs:
AllowAdjacentOneLineDefs: true

Encoding:
Enabled: false

EndAlignment:
AlignWith: variable

HashSyntax:
EnforcedStyle: hash_rockets

Style/IndentHash:
EnforcedStyle: consistent

Loop:
Enabled: false

PredicateName:
Enabled: false

RegexpLiteral:
Enabled: false

Semicolon:
AllowAsExpressionSeparator: true

Style/TrailingComma:
EnforcedStyleForMultiline: comma

Style/TrivialAccessors:
AllowDSLWriters: true
AllowPredicates: true
ExactNameMatch: true
52 changes: 52 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2014-07-23 21:41:36 -0700 using RuboCop version 0.24.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 27
Lint/AmbiguousRegexpLiteral:
Enabled: false

# Offense count: 1
Lint/HandleExceptions:
Enabled: false

# Offense count: 1
# Configuration parameters: CountComments.
Style/ClassLength:
Max: 324

# Offense count: 3
Style/CyclomaticComplexity:
Max: 14

# Offense count: 81
Style/Documentation:
Enabled: false

# Offense count: 1
# Configuration parameters: Exclude.
Style/FileName:
Enabled: false

# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Enabled: false

# Offense count: 273
# Configuration parameters: AllowURI.
Style/LineLength:
Max: 180

# Offense count: 10
# Configuration parameters: CountComments.
Style/MethodLength:
Max: 52

# Offense count: 2
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/Next:
Enabled: false
33 changes: 17 additions & 16 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'appraisal'

task :default => :spec
RSpec::Core::RakeTask.new
RuboCop::RakeTask.new

RSpec::Core::RakeTask.new(:spec) do |spec|
end
task :default => [:spec, :rubocop]

namespace :db do
desc 'Build the databases for tests'
task :build_databases do
pg_spec = {
:adapter => 'postgresql',
:host => 'localhost',
:username => (ENV['POSTGRES_USER'] || "postgres"),
:encoding => 'utf8'
:username => (ENV['POSTGRES_USER'] || 'postgres'),
:encoding => 'utf8',
}

mysql_spec = {
:adapter => 'mysql2',
:host => 'localhost',
:username => (ENV['MYSQL_USER'] || "root"),
:encoding => 'utf8'
:username => (ENV['MYSQL_USER'] || 'root'),
:encoding => 'utf8',
}

%x( rm -f /tmp/database.sqlite3 )
` rm -f /tmp/database.sqlite3 `

require "active_record"
require 'active_record'

# Connects to PostgreSQL
ActiveRecord::Base.establish_connection(pg_spec.merge('database' => 'postgres', 'schema_search_path' => 'public'))
Expand All @@ -49,9 +50,9 @@ namespace :db do

desc 'Create tables on tests databases'
task :create_tables do
require "octopus"
require 'octopus'
# Set the octopus variable directory to spec dir, in order to load the config/shards.yml file.
Octopus.instance_variable_set(:@directory, "#{File.dirname(__FILE__)}/spec/" )
Octopus.instance_variable_set(:@directory, "#{File.dirname(__FILE__)}/spec/")

# Require the database connection
require "#{File.dirname(__FILE__)}/spec/support/database_connection"
Expand All @@ -61,9 +62,9 @@ namespace :db do
shard_symbols.each do |shard_symbol|
# Rails 3.1 needs to do some introspection around the base class, which requires
# the model be a descendent of ActiveRecord::Base.
class BlankModel < ActiveRecord::Base; end;
class BlankModel < ActiveRecord::Base; end

BlankModel.using(shard_symbol).connection.initialize_schema_migrations_table()
BlankModel.using(shard_symbol).connection.initialize_schema_migrations_table

BlankModel.using(shard_symbol).connection.create_table(:users) do |u|
u.string :name
Expand Down Expand Up @@ -148,14 +149,14 @@ namespace :db do

BlankModel.using(shard_symbol).connection.create_table(:weapons) do |u|
u.integer :mmorpg_player_id
u.string :name
u.string :hand
u.string :name
u.string :hand
end

BlankModel.using(shard_symbol).connection.create_table(:skills) do |u|
u.integer :mmorpg_player_id
u.integer :weapon_id
u.string :name
u.string :name
end
end
end
Expand Down
25 changes: 13 additions & 12 deletions ar-octopus.gemspec
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "octopus/version"
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'octopus/version'

Gem::Specification.new do |s|
s.name = "ar-octopus"
s.name = 'ar-octopus'
s.version = Octopus::VERSION
s.authors = ["Thiago Pradi", "Mike Perham", "Gabriel Sobrinho"]
s.email = ["tchandy@gmail.com", "mperham@gmail.com", "gabriel.sobrinho@gmail.com"]
s.homepage = "https://github.com/tchandy/octopus"
s.summary = %q{Easy Database Sharding for ActiveRecord}
s.description = %q{This gem allows you to use sharded databases with ActiveRecord. This also provides a interface for replication and for running migrations with multiples shards.}
s.authors = ['Thiago Pradi', 'Mike Perham', 'Gabriel Sobrinho']
s.email = ['tchandy@gmail.com', 'mperham@gmail.com', 'gabriel.sobrinho@gmail.com']
s.homepage = 'https://github.com/tchandy/octopus'
s.summary = 'Easy Database Sharding for ActiveRecord'
s.description = 'This gem allows you to use sharded databases with ActiveRecord. This also provides a interface for replication and for running migrations with multiples shards.'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.require_paths = ['lib']

s.post_install_message = "Important: If you are upgrading from < Octopus 0.5.0 you need to run:\n" \
"$ rake octopus:copy_schema_versions\n\n" \
"Octopus now stores schema version information in each shard and migrations will not " \
"work properly unless this task is invoked."
'Octopus now stores schema version information in each shard and migrations will not ' \
'work properly unless this task is invoked.'

s.add_dependency 'activerecord', '>= 3.2.0'
s.add_dependency 'activesupport', '>= 3.2.0'
Expand All @@ -29,6 +29,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'pg', '>= 0.11.0'
s.add_development_dependency 'rake', '>= 0.8.7'
s.add_development_dependency 'rspec', '>= 3'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'sqlite3', '>= 1.3.4'

if RUBY_VERSION < '2.0.0'
Expand Down
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require File.join(File.dirname(__FILE__), 'rails', 'init')
require File.join(File.dirname(__FILE__), 'rails', 'init')
2 changes: 1 addition & 1 deletion lib/ar-octopus.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require "octopus"
require 'octopus'
71 changes: 34 additions & 37 deletions lib/octopus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
require 'active_support/version'
require 'active_support/core_ext/class'

require "yaml"
require "erb"
require 'yaml'
require 'erb'

module Octopus
def self.env()
def self.env
@env ||= 'octopus'
end

def self.rails_env()
def self.rails_env
@rails_env ||= self.rails? ? Rails.env.to_s : 'shards'
end

def self.config
@config ||= begin
file_name = Octopus.directory() + "/config/shards.yml"
file_name = Octopus.directory + '/config/shards.yml'

if File.exists?(file_name) || File.symlink?(file_name)
config ||= HashWithIndifferentAccess.new(YAML.load(ERB.new(File.read(file_name)).result))[Octopus.env()]
if File.exist?(file_name) || File.symlink?(file_name)
config ||= HashWithIndifferentAccess.new(YAML.load(ERB.new(File.read(file_name)).result))[Octopus.env]
else
config ||= HashWithIndifferentAccess.new
end
Expand All @@ -45,7 +45,7 @@ def self.enabled?

# Returns the Rails.root_to_s when you are using rails
# Running the current directory in a generic Ruby process
def self.directory()
def self.directory
@directory ||= defined?(Rails) ? Rails.root.to_s : Dir.pwd
end

Expand Down Expand Up @@ -81,7 +81,7 @@ def self.rails?
end

def self.shards=(shards)
config[rails_env()] = HashWithIndifferentAccess.new(shards)
config[rails_env] = HashWithIndifferentAccess.new(shards)
ActiveRecord::Base.connection.initialize_shards(@config)
end

Expand All @@ -95,36 +95,33 @@ def self.using(shard, &block)
end
end

def self.fully_replicated(&block)
old_fully_replicated = Thread.current["octopus.fully_replicated"]
Thread.current["octopus.fully_replicated"] = true
def self.fully_replicated(&_block)
old_fully_replicated = Thread.current['octopus.fully_replicated']
Thread.current['octopus.fully_replicated'] = true
yield
ensure
Thread.current["octopus.fully_replicated"] = old_fully_replicated
Thread.current['octopus.fully_replicated'] = old_fully_replicated
end
end

require "octopus/shard_tracking"
require "octopus/shard_tracking/attribute"
require "octopus/shard_tracking/dynamic"

require "octopus/model"
require "octopus/migration"
require "octopus/association"
require "octopus/collection_association"
require "octopus/has_and_belongs_to_many_association" unless Octopus.rails41?
require "octopus/association_shard_tracking"
require "octopus/persistence"
require "octopus/log_subscriber"
require "octopus/abstract_adapter"
require "octopus/singular_association"

if defined?(::Rails)
require "octopus/railtie"
end


require "octopus/proxy"
require "octopus/collection_proxy"
require "octopus/relation_proxy"
require "octopus/scope_proxy"
require 'octopus/shard_tracking'
require 'octopus/shard_tracking/attribute'
require 'octopus/shard_tracking/dynamic'

require 'octopus/model'
require 'octopus/migration'
require 'octopus/association'
require 'octopus/collection_association'
require 'octopus/has_and_belongs_to_many_association' unless Octopus.rails41?
require 'octopus/association_shard_tracking'
require 'octopus/persistence'
require 'octopus/log_subscriber'
require 'octopus/abstract_adapter'
require 'octopus/singular_association'

require 'octopus/railtie' if defined?(::Rails)

require 'octopus/proxy'
require 'octopus/collection_proxy'
require 'octopus/relation_proxy'
require 'octopus/scope_proxy'
2 changes: 0 additions & 2 deletions lib/octopus/abstract_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
module Octopus
module AbstractAdapter
module OctopusShard

parent = Octopus.rails3? ? ActiveSupport::BasicObject : ActiveSupport::ProxyObject

class InstrumenterDecorator < parent
Expand Down Expand Up @@ -33,7 +32,6 @@ def initialize_with_octopus_shard(*args)
initialize_without_octopus_shard(*args)
@instrumenter = InstrumenterDecorator.new(self, @instrumenter)
end

end
end
end
Expand Down
14 changes: 8 additions & 6 deletions lib/octopus/association.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module Octopus::Association
def self.included(base)
base.send(:include, Octopus::ShardTracking::Dynamic)
end
module Octopus
module Association
def self.included(base)
base.send(:include, Octopus::ShardTracking::Dynamic)
end

def current_shard
owner.current_shard
def current_shard
owner.current_shard
end
end
end

Expand Down
Loading

0 comments on commit 73131fb

Please sign in to comment.