Class: Pgai::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/pgai/config.rb

Defined Under Namespace

Classes: Clone

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Config

Returns a new instance of Config.

Yields:

  • (_self)

Yield Parameters:

  • _self (Pgai::Config)

    the object that the method was called on



29
30
31
# File 'lib/pgai/config.rb', line 29

def initialize
  yield self if block_given?
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



17
18
19
# File 'lib/pgai/config.rb', line 17

def access_token
  @access_token
end

#clone_prefixObject

Returns the value of attribute clone_prefix.



15
16
17
# File 'lib/pgai/config.rb', line 15

def clone_prefix
  @clone_prefix
end

#dbnameObject

Returns the value of attribute dbname.



16
17
18
# File 'lib/pgai/config.rb', line 16

def dbname
  @dbname
end

#pathObject

Returns the value of attribute path.



19
20
21
# File 'lib/pgai/config.rb', line 19

def path
  @path
end

#proxyObject

Returns the value of attribute proxy.



18
19
20
# File 'lib/pgai/config.rb', line 18

def proxy
  @proxy
end

Class Method Details

.loadObject



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(options = {})
  store.transaction do
    store[:environments] ||= {}
    store[:environments].merge!(options[:alias] => options)
  end
end

#enviromentsObject



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_storeObject



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(options)
  store.transaction do
    store[:clone_prefix] = options[:prefix]
    store[:dbname] = options[:dbname]
    store[:access_token] = options[:token]
    store[:proxy] = options[:proxy]
    store[:path] = options[:path]
    store[:clones] = {}
  end
end