Module: TotemActiverecord
- Defined in:
- lib/totem_activerecord.rb,
lib/totem_activerecord/version.rb,
lib/totem_activerecord/shell_cmds/db.rb
Defined Under Namespace
Modules: ShellCmds
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
- .config ⇒ Object
- .config_path ⇒ Object
- .connect ⇒ Object
- .connected? ⇒ Boolean
- .disconnect ⇒ Object
- .migrations_path ⇒ Object
- .reconnect ⇒ Object
Class Method Details
.config ⇒ Object
16 17 18 |
# File 'lib/totem_activerecord.rb', line 16 def self.config return (@config ||= YAML.load_file(config_path)[Totem.env]) end |
.config_path ⇒ Object
8 9 10 |
# File 'lib/totem_activerecord.rb', line 8 def self.config_path return File.join(Totem.root, 'config', 'database.yml') end |
.connect ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/totem_activerecord.rb', line 20 def self.connect return false if connected? begin ActiveRecord::Base.establish_connection(TotemActiverecord.config) rescue Exception => e puts "Failed to establish DB connection: #{e.message}\n#{e.backtrace.join("\n")}" return false end return true end |
.connected? ⇒ Boolean
48 49 50 |
# File 'lib/totem_activerecord.rb', line 48 def self.connected? return !!ActiveRecord::Base.connected? end |
.disconnect ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/totem_activerecord.rb', line 33 def self.disconnect return false unless connected? ActiveRecord::Base.connection_pool.disconnect! return true end |
.migrations_path ⇒ Object
12 13 14 |
# File 'lib/totem_activerecord.rb', line 12 def self.migrations_path return File.join(Totem.root, 'db', 'migrate') end |
.reconnect ⇒ Object
41 42 43 44 45 46 |
# File 'lib/totem_activerecord.rb', line 41 def self.reconnect disconnect connect return true end |