Class: Poke::GroupConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/poke/group_config.rb

Defined Under Namespace

Classes: InvalidEnv

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = {}) ⇒ GroupConfig

Returns a new instance of GroupConfig.



13
14
15
# File 'lib/poke/group_config.rb', line 13

def initialize(values = {})
  @values = values
end

Class Method Details

.from_path(path) ⇒ Object



9
10
11
# File 'lib/poke/group_config.rb', line 9

def self.from_path(path)
  new(JSON.parse(File.read(path)))
end

Instance Method Details

#default_envObject



25
26
27
# File 'lib/poke/group_config.rb', line 25

def default_env
  @values.fetch('default_env', @values['envs'].keys.first)
end

#default_env=(value) ⇒ Object

Raises:



29
30
31
32
33
# File 'lib/poke/group_config.rb', line 29

def default_env=(value)
  raise InvalidEnv unless valid_env?(value)

  @values['default_env'] = value
end

#envsObject



35
36
37
# File 'lib/poke/group_config.rb', line 35

def envs
  @values['envs'].keys
end

#save_to(path) ⇒ Object



17
18
19
# File 'lib/poke/group_config.rb', line 17

def save_to(path)
  File.write(path, @values.to_json)
end

#valid_env?(env) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/poke/group_config.rb', line 21

def valid_env?(env)
  @values['envs'].key?(env)
end

#variables(env) ⇒ Object



39
40
41
# File 'lib/poke/group_config.rb', line 39

def variables(env)
  @values['envs'][env]
end