Class: VMC::KNIFE::Root

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

Overview

Read/Write the JSON for a recipe. Does not map the actual JSON into a new ruby object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Root

Returns a new instance of Root.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/vmc_knife/vmc_knife.rb', line 12

def initialize(data)
  if data.kind_of? Hash
    @wrapped = data
  elsif data.kind_of? String
    @wrapped = VMC::KNIFE::JSON_EXPANDER.expand_json data
  elsif data.kind_of? Root
    @wrapped = data.wrapped
  else
    raise "Unexpected data #{data}"
  end
end

Instance Attribute Details

#wrappedObject

Returns the value of attribute wrapped.



11
12
13
# File 'lib/vmc_knife/vmc_knife.rb', line 11

def wrapped
  @wrapped
end

Instance Method Details

#first_recipe(name) ⇒ Object



44
45
46
# File 'lib/vmc_knife/vmc_knife.rb', line 44

def first_recipe(name)
  Recipe.new self, @wrapped['recipes'][0] unless @wrapped['recipes'].empty?
end

#recipe(name) ⇒ Object



40
41
42
43
# File 'lib/vmc_knife/vmc_knife.rb', line 40

def recipe(name)
  res = @wrapped['recipes'].select {|v| v['name'] == name}
  Recipe.new self, res.first unless res.empty?
end

#recipes(regexp = nil) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/vmc_knife/vmc_knife.rb', line 32

def recipes(regexp=nil)
  regexp||=/.*/
  res = Array.new
  @wrapped['recipes'].each do |recipe|
    res << Recipe.new(self, recipe) if (regexp =~ recipe['name'])
  end
  res
end

#sub_domainObject



23
24
25
# File 'lib/vmc_knife/vmc_knife.rb', line 23

def sub_domain()
  @wrapped['sub_domain']
end

#targetObject



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

def target()
  @wrapped['target']
end

#to_jsonObject



47
48
49
# File 'lib/vmc_knife/vmc_knife.rb', line 47

def to_json()
  @wrapped.to_json
end

#userObject



26
27
28
# File 'lib/vmc_knife/vmc_knife.rb', line 26

def user()
  @wrapped['user']
end