Module: Octopus
- Defined in:
- lib/octopus/rails3/log_subscriber.rb,
lib/octopus.rb,
lib/octopus/version.rb,
lib/octopus/rails3/persistence.rb,
lib/octopus/rails3/abstract_adapter.rb
Overview
Implementation courtesy of db-charmer.
Defined Under Namespace
Modules: AbstractAdapter, Association, AssociationCollection, HasAndBelongsToManyAssociation, LogSubscriber, Migration, MigrationProxy, Migrator, Model, Rails3, SingularAssociation, UnknownMigrationVersionError
Classes: Proxy, ScopeProxy
Constant Summary
collapse
- VERSION =
'0.8.0'
Class Method Summary
collapse
Class Method Details
.config ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/octopus.rb', line 17
def self.config
@config ||= begin
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()]
else
config ||= HashWithIndifferentAccess.new
end
config
end
end
|
.directory ⇒ Object
Returns the Rails.root_to_s when you are using rails Running the current directory in a generic Ruby process
48
49
50
|
# File 'lib/octopus.rb', line 48
def self.directory()
@directory ||= defined?(Rails) ? Rails.root.to_s : Dir.pwd
end
|
.enabled? ⇒ Boolean
Public: Whether or not Octopus is configured and should hook into the current environment. Checks the environments config option for the Rails environment by default.
Returns a boolean
36
37
38
39
40
41
42
43
44
|
# File 'lib/octopus.rb', line 36
def self.enabled?
if defined?(::Rails)
Octopus.environments.include?(Rails.env.to_s)
else
Octopus.config
end
end
|
.env ⇒ Object
9
10
11
|
# File 'lib/octopus.rb', line 9
def self.env()
@env ||= 'octopus'
end
|
.environments ⇒ Object
63
64
65
|
# File 'lib/octopus.rb', line 63
def self.environments
@environments ||= config['environments'] || ['production']
end
|
.environments=(environments) ⇒ Object
59
60
61
|
# File 'lib/octopus.rb', line 59
def self.environments=(environments)
@environments = environments.map { |element| element.to_s }
end
|
.rails3? ⇒ Boolean
67
68
69
|
# File 'lib/octopus.rb', line 67
def self.rails3?
ActiveRecord::VERSION::MAJOR <= 3
end
|
.rails4? ⇒ Boolean
71
72
73
|
# File 'lib/octopus.rb', line 71
def self.rails4?
ActiveRecord::VERSION::MAJOR >= 4
end
|
.rails? ⇒ Boolean
75
76
77
|
# File 'lib/octopus.rb', line 75
def self.rails?
defined?(Rails)
end
|
.rails_env ⇒ Object
13
14
15
|
# File 'lib/octopus.rb', line 13
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’
55
56
57
|
# File 'lib/octopus.rb', line 55
def self.setup
yield self
end
|
.shards=(shards) ⇒ Object
79
80
81
82
|
# File 'lib/octopus.rb', line 79
def self.shards=(shards)
config[rails_env()] = HashWithIndifferentAccess.new(shards)
ActiveRecord::Base.connection.initialize_shards(@config)
end
|
.using(shard, &block) ⇒ Object
84
85
86
87
88
89
90
91
92
|
# File 'lib/octopus.rb', line 84
def self.using(shard, &block)
conn = ActiveRecord::Base.connection
if conn.is_a?(Octopus::Proxy)
conn.run_queries_on_shard(shard, &block)
else
yield
end
end
|