Class: Spore::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/spore/parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Parser

Returns a new instance of Parser.



13
14
15
16
17
# File 'lib/spore/parser.rb', line 13

def initialize(config)
  @config = config
  spore = JSON.parse(File.read config.spore_file)
  translate(spore["id"], spore["envs"][config.environment])
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



12
13
14
# File 'lib/spore/parser.rb', line 12

def hash
  @hash
end

Class Method Details

.callObject



6
7
8
9
# File 'lib/spore/parser.rb', line 6

def call
  config = Spore::Config.load
  new(config).hash
end

Instance Method Details

#translate(app_id, hash) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/spore/parser.rb', line 19

def translate(app_id, hash)
  @hash = {}
  hash.each do |key, value|
    # Translate APP_ENV to RAILS_ENV
    key = "RAILS_ENV" if key == "APP_ENV"
    @hash[key] = @config.fetch(app_id, value)
  end
  @hash
end