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
.config ⇒ Object
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
|
.directory ⇒ Object
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
|
.env ⇒ Object
5
6
7
|
# File 'lib/octopus.rb', line 5
def self.env()
@env ||= 'octopus'
end
|
.environments ⇒ Object
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
44
45
46
|
# File 'lib/octopus.rb', line 44
def self.rails3?
ActiveRecord::VERSION::MAJOR == 3
end
|
.rails? ⇒ Boolean
48
49
50
|
# File 'lib/octopus.rb', line 48
def self.rails?
defined?(Rails)
end
|
.rails_env ⇒ Object
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’
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
|