Module: EYCli::SmartyParser

Included in:
Model::Base
Defined in:
lib/ey_cli/smarty_parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(body, klass = self) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/ey_cli/smarty_parser.rb', line 3

def parse(body, klass = self)
  case body
  when Hash
    klass.new smarty(body)
  when Array
    body.map { |item| parse(item, klass) }
  else
    body
  end
end

#smarty(hash) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ey_cli/smarty_parser.rb', line 14

def smarty(hash)
  hash.each do |key, value|
    case key
    when /accounts?/
      hash[key] = parse(value, EYCli::Model::Account)
    when /apps?/
      hash[key] = parse(value, EYCli::Model::App)
    when /environments?/
      hash[key] = parse(value, EYCli::Model::Environment)
    when /deployments?/
      hash[key] = parse(value, EYCli::Model::Deployment)
    else
      hash[key] = parse(value, Hashie::Mash)
    end
  end
end