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



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

def self.config()
  @config ||= HashWithIndifferentAccess.new(YAML.load_file(Octopus.directory() + "/config/shards.yml"))[Octopus.env()]

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

  @config
end

.directoryObject

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



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

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

.envObject



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

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

.enviromentsObject



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

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

.enviroments=(enviroments) ⇒ Object



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

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

.rails3?Boolean

Returns:

  • (Boolean)


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

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

.rails?Boolean

Returns:

  • (Boolean)


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

def self.rails?
  defined?(Rails) 
end

.rails_envObject



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

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



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

def self.setup
  yield self
end

.using(shard, &block) ⇒ Object



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

def self.using(shard, &block)
  ActiveRecord::Base.hijack_initializer()

  if ActiveRecord::Base.connection.is_a?(Octopus::Proxy)
    ActiveRecord::Base.connection.run_queries_on_shard(shard, &block)
  else
    yield
  end
end