Module: Octopus

Defined in:
lib/octopus.rb,
lib/octopus/rails2/association.rb,
lib/octopus/rails2/persistence.rb,
lib/octopus/rails3/association.rb,
lib/octopus/rails3/persistence.rb

Defined Under Namespace

Modules: Association, AssociationCollection, HasAndBelongsToManyAssociation, Migration, Model, Rails2, Rails3 Classes: Proxy, ScopeProxy

Class Method Summary collapse

Class Method Details

.configObject



13
14
15
16
17
18
19
20
21
# File 'lib/octopus.rb', line 13

def self.config()
  @config ||= HashWithIndifferentAccess.new(YAML.load(ERB.new(File.open(Octopus.directory() + "/config/shards.yml").read()).result))[Octopus.env()]

  if @config && @config['environments']
    self.environments = @config['environments']
  end

  @config
end

.directoryObject

Returns the Rails.root_to_s when you are using rails Running the current directory in a generic Ruby process



25
26
27
# File 'lib/octopus.rb', line 25

def self.directory()
  @directory ||= defined?(Rails) ?  Rails.root.to_s : Dir.pwd     
end

.envObject



5
6
7
# File 'lib/octopus.rb', line 5

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

.environmentsObject



40
41
42
# File 'lib/octopus.rb', line 40

def self.environments
  @environments || ['production']
end

.environments=(environments) ⇒ Object



36
37
38
# File 'lib/octopus.rb', line 36

def self.environments=(environments)
  @environments = environments.map { |element| element.to_s }
end

.rails3?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/octopus.rb', line 44

def self.rails3?
  ActiveRecord::VERSION::MAJOR == 3
end

.rails?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/octopus.rb', line 48

def self.rails?
  defined?(Rails) 
end

.rails_envObject



9
10
11
# File 'lib/octopus.rb', line 9

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

.setup {|_self| ... } ⇒ Object

This is the default way to do Octopus Setup Available variables: :enviroments => the enviroments that octopus will run. default: ‘production’

Yields:

  • (_self)

Yield Parameters:

  • _self (Octopus)

    the object that the method was called on



32
33
34
# File 'lib/octopus.rb', line 32

def self.setup
  yield self
end

.using(shard, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/octopus.rb', line 52

def self.using(shard, &block)
  ActiveRecord::Base.hijack_initializer()
  conn = ActiveRecord::Base.connection
  
  if conn.is_a?(Octopus::Proxy)
    conn.run_queries_on_shard(shard, &block)
  else
    yield
  end
end