Class: Pgai::Config
- Inherits:
-
Object
- Object
- Pgai::Config
- Defined in:
- lib/pgai/config.rb
Defined Under Namespace
Classes: Clone
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#clone_prefix ⇒ Object
Returns the value of attribute clone_prefix.
-
#dbname ⇒ Object
Returns the value of attribute dbname.
-
#path ⇒ Object
Returns the value of attribute path.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
Class Method Summary collapse
Instance Method Summary collapse
- #add_env(options = {}) ⇒ Object
- #enviroments ⇒ Object
- #find_clone(id) ⇒ Object
-
#initialize {|_self| ... } ⇒ Config
constructor
A new instance of Config.
- #load_from_store ⇒ Object
- #persist_clone(id, attributes = {}) ⇒ Object
- #remove_clone(id) ⇒ Object
- #remove_env(env_alias) ⇒ Object
- #write(options) ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Config
Returns a new instance of Config.
29 30 31 |
# File 'lib/pgai/config.rb', line 29 def initialize yield self if block_given? end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
17 18 19 |
# File 'lib/pgai/config.rb', line 17 def access_token @access_token end |
#clone_prefix ⇒ Object
Returns the value of attribute clone_prefix.
15 16 17 |
# File 'lib/pgai/config.rb', line 15 def clone_prefix @clone_prefix end |
#dbname ⇒ Object
Returns the value of attribute dbname.
16 17 18 |
# File 'lib/pgai/config.rb', line 16 def dbname @dbname end |
#path ⇒ Object
Returns the value of attribute path.
19 20 21 |
# File 'lib/pgai/config.rb', line 19 def path @path end |
#proxy ⇒ Object
Returns the value of attribute proxy.
18 19 20 |
# File 'lib/pgai/config.rb', line 18 def proxy @proxy end |
Class Method Details
.load ⇒ Object
21 22 23 |
# File 'lib/pgai/config.rb', line 21 def self.load new { |config| config.load_from_store } end |
.persist(data) ⇒ Object
25 26 27 |
# File 'lib/pgai/config.rb', line 25 def self.persist(data) new { |config| config.write(data) } end |
Instance Method Details
#add_env(options = {}) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/pgai/config.rb', line 78 def add_env( = {}) store.transaction do store[:environments] ||= {} store[:environments].merge!([:alias] => ) end end |
#enviroments ⇒ Object
92 93 94 95 96 |
# File 'lib/pgai/config.rb', line 92 def enviroments store.transaction(true) do store[:environments] || {} end end |
#find_clone(id) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/pgai/config.rb', line 54 def find_clone(id) store.transaction(true) do clones = store[:clones] || {} Clone.new(clones[id]) if clones[id] end end |
#load_from_store ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/pgai/config.rb', line 33 def load_from_store store.transaction(true) do self.clone_prefix = store[:clone_prefix] self.dbname = store[:dbname] self.access_token = store[:access_token] self.proxy = store[:proxy] self.path = store[:path] end end |
#persist_clone(id, attributes = {}) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/pgai/config.rb', line 69 def persist_clone(id, attributes = {}) store.transaction do store[:clones] = {} store[:clones].merge!(id => attributes) end Clone.new(attributes) end |
#remove_clone(id) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/pgai/config.rb', line 62 def remove_clone(id) store.transaction do store[:clones] ||= {} store[:clones] = store[:clones].except(id) end end |
#remove_env(env_alias) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/pgai/config.rb', line 85 def remove_env(env_alias) store.transaction do store[:environments] ||= {} store[:environments] = store[:environments].except(env_alias) end end |
#write(options) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pgai/config.rb', line 43 def write() store.transaction do store[:clone_prefix] = [:prefix] store[:dbname] = [:dbname] store[:access_token] = [:token] store[:proxy] = [:proxy] store[:path] = [:path] store[:clones] = {} end end |