Class: GTA::LocalDB
Instance Attribute Summary collapse
-
#database_config_path ⇒ Object
readonly
Returns the value of attribute database_config_path.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Class Method Summary collapse
Instance Method Summary collapse
- #_username ⇒ Object
- #config ⇒ Object
- #database ⇒ Object
- #file_contents ⇒ Object
-
#initialize(env, database_config_path = nil) ⇒ LocalDB
constructor
A new instance of LocalDB.
- #load(backup_path) ⇒ Object
- #parsed_config ⇒ Object
- #username ⇒ Object
Methods included from Sh
Constructor Details
#initialize(env, database_config_path = nil) ⇒ LocalDB
Returns a new instance of LocalDB.
7 8 9 10 |
# File 'lib/gta/local_db.rb', line 7 def initialize(env, database_config_path=nil) @env = env @database_config_path = database_config_path || self.class.default_database_config_path end |
Instance Attribute Details
#database_config_path ⇒ Object (readonly)
Returns the value of attribute database_config_path.
5 6 7 |
# File 'lib/gta/local_db.rb', line 5 def database_config_path @database_config_path end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
5 6 7 |
# File 'lib/gta/local_db.rb', line 5 def env @env end |
Class Method Details
.default_database_config_path ⇒ Object
40 41 42 |
# File 'lib/gta/local_db.rb', line 40 def self.default_database_config_path "#{Dir.pwd}/config/database.yml" end |
.local_database_env ⇒ Object
44 45 46 |
# File 'lib/gta/local_db.rb', line 44 def self.local_database_env ENV['RAILS_ENV'] || ENV['GTA_LOCAL_ENV'] end |
Instance Method Details
#_username ⇒ Object
28 29 30 |
# File 'lib/gta/local_db.rb', line 28 def _username config['username'] || config['user'] end |
#config ⇒ Object
16 17 18 |
# File 'lib/gta/local_db.rb', line 16 def config @config ||= parsed_config[env] end |
#database ⇒ Object
36 37 38 |
# File 'lib/gta/local_db.rb', line 36 def database config['database'] ? " -d #{config['database']}" : '' end |
#file_contents ⇒ Object
20 21 22 |
# File 'lib/gta/local_db.rb', line 20 def file_contents File.read(database_config_path) end |
#load(backup_path) ⇒ Object
12 13 14 |
# File 'lib/gta/local_db.rb', line 12 def load(backup_path) sh("pg_restore --verbose --clean --no-acl --no-owner -h localhost#{username}#{database} #{backup_path}") end |
#parsed_config ⇒ Object
24 25 26 |
# File 'lib/gta/local_db.rb', line 24 def parsed_config database_config_path.match(/yml$/) ? YAML.load(file_contents) : JSON.parse(file_contents) end |
#username ⇒ Object
32 33 34 |
# File 'lib/gta/local_db.rb', line 32 def username _username ? " -U #{_username}" : '' end |