Class: Megam::CloudTemplate
- Inherits:
-
Object
- Object
- Megam::CloudTemplate
- Defined in:
- lib/megam/core/cloudtemplate.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cctype(arg = nil) ⇒ Object
- #cloud_instruction_group(arg = nil) ⇒ Object
- #cloud_instruction_group_by_name(arg = nil) ⇒ Object
- #cloud_template ⇒ Object
- #error? ⇒ Boolean
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
-
#initialize ⇒ CloudTemplate
constructor
A new instance of CloudTemplate.
-
#lookup_by_group_name(group) ⇒ Object
returns a cloud instruction for a particular group.
-
#lookup_by_instruction(group, action) ⇒ Object
returns a cloud instruction for a particular group, action.
-
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash.
-
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ CloudTemplate
Returns a new instance of CloudTemplate.
18 19 20 21 22 |
# File 'lib/megam/core/cloudtemplate.rb', line 18 def initialize @cctype = nil @cloud_instruction_group = nil @cloud_instruction_group_by_name = Hash.new end |
Class Method Details
.from_hash(o) ⇒ Object
111 112 113 114 115 |
# File 'lib/megam/core/cloudtemplate.rb', line 111 def self.from_hash(o) cloudtemplate = self.new() cloudtemplate.from_hash(o) cloudtemplate end |
.json_create(o) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/megam/core/cloudtemplate.rb', line 101 def self.json_create(o) cloudtemplate = new cloudtemplate.cctype(o["cctype"]) if o.has_key?("cctype") cloudtemplate.cloud_instruction_group(o["cloud_instruction_group"]) if o.has_key?("cloud_instruction_group") cloudtemplate.cloud_instruction_group.each do |single_cig| cloudtemplate.cloud_instruction_group_by_name[single_cig.group] = single_cig end cloudtemplate end |
Instance Method Details
#cctype(arg = nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/megam/core/cloudtemplate.rb', line 28 def cctype(arg=nil) if arg != nil @cctype = arg else @cctype end end |
#cloud_instruction_group(arg = nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/megam/core/cloudtemplate.rb', line 36 def cloud_instruction_group(arg=nil) if arg != nil @cloud_instruction_group = arg else @cloud_instruction_group end end |
#cloud_instruction_group_by_name(arg = nil) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/megam/core/cloudtemplate.rb', line 44 def cloud_instruction_group_by_name(arg=nil) if arg != nil @cloud_instruction_group_by_name = arg else @cloud_instruction_group_by_name end end |
#cloud_template ⇒ Object
24 25 26 |
# File 'lib/megam/core/cloudtemplate.rb', line 24 def cloud_template self end |
#error? ⇒ Boolean
71 72 73 |
# File 'lib/megam/core/cloudtemplate.rb', line 71 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/megam/core/cloudtemplate.rb', line 92 def for_json result = { "cctype" => cctype, "cloud_instruction_group" => cloud_instruction_group } result end |
#from_hash(o) ⇒ Object
117 118 119 120 |
# File 'lib/megam/core/cloudtemplate.rb', line 117 def from_hash(o) @cctype = o[:cctype] if o.has_key?(:cctype) self end |
#lookup_by_group_name(group) ⇒ Object
returns a cloud instruction for a particular group
53 54 55 56 57 58 59 |
# File 'lib/megam/core/cloudtemplate.rb', line 53 def lookup_by_group_name(group) res =@cloud_instruction_group_by_name[group] unless res raise ArgumentError, "Cannot find a cloudgroup matching #{group} (did you define it first?)" end res end |
#lookup_by_instruction(group, action) ⇒ Object
returns a cloud instruction for a particular group, action
62 63 64 65 66 67 68 69 |
# File 'lib/megam/core/cloudtemplate.rb', line 62 def lookup_by_instruction(group,action) single_cig = lookup_by_group_name(group) #single_cig.cloud_instructions_array.select { |cloudinstructions| cloudinstructions.lookup(action) } single_cig.cloud_instructions_array.each do |cia| @ci= cia.lookup(action) end @ci end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
76 77 78 79 80 81 82 83 84 |
# File 'lib/megam/core/cloudtemplate.rb', line 76 def to_hash index_hash = Hash.new index_hash["json_claz"] = self.class.name index_hash["cctype"] = cctype cloud_instruction_group.each do |single_cig| index_hash[single_cig.group] = single_cig end index_hash end |
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.
88 89 90 |
# File 'lib/megam/core/cloudtemplate.rb', line 88 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
122 123 124 |
# File 'lib/megam/core/cloudtemplate.rb', line 122 def to_s Megam::Stuff.styled_hash(to_hash) end |