Class: Reactor::Cm::ObjClass
- Inherits:
-
Object
- Object
- Reactor::Cm::ObjClass
- Defined in:
- lib/reactor/cm/obj_class.rb
Class Method Summary collapse
- .create(name, type) ⇒ Object
- .exists?(name) ⇒ Boolean
- .get(name) ⇒ Object
- .rename(current_name, new_name) ⇒ Object
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes=(attr_arr) ⇒ Object
- #delete! ⇒ Object
- #has_attribute?(attr_name) ⇒ Boolean
- #mandatory_attributes ⇒ Object
- #mandatory_attributes=(attr_arr) ⇒ Object
- #preset(key, value) ⇒ Object
- #preset_attributes ⇒ Object
- #save! ⇒ Object
- #set(key, value, options = {}) ⇒ Object
Class Method Details
.create(name, type) ⇒ Object
17 18 19 20 21 |
# File 'lib/reactor/cm/obj_class.rb', line 17 def self.create(name, type) klass = ObjClass.new klass.send(:create, name, type) klass end |
.exists?(name) ⇒ Boolean
8 9 10 11 12 13 14 15 |
# File 'lib/reactor/cm/obj_class.rb', line 8 def self.exists?(name) klass = ObjClass.new begin klass.send(:get, name).ok? rescue StandardError false end end |
.get(name) ⇒ Object
23 24 25 26 27 |
# File 'lib/reactor/cm/obj_class.rb', line 23 def self.get(name) klass = ObjClass.new klass.send(:get, name) klass end |
.rename(current_name, new_name) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/reactor/cm/obj_class.rb', line 29 def self.rename(current_name, new_name) request = XmlRequest.prepare do |xml| xml.tag!("objClass-where") do xml.tag!("name", current_name) end xml.tag!("objClass-set") do xml.tag!("name", new_name) end end request.execute! end |
Instance Method Details
#attributes ⇒ Object
115 116 117 |
# File 'lib/reactor/cm/obj_class.rb', line 115 def attributes __attributes_get("attributes") end |
#attributes=(attr_arr) ⇒ Object
119 120 121 |
# File 'lib/reactor/cm/obj_class.rb', line 119 def attributes=(attr_arr) __attributes_set("attributes", attr_arr) end |
#delete! ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/reactor/cm/obj_class.rb', line 131 def delete! request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, "name", @name) xml.tag!("#{base_name}-delete") end request.execute! end |
#has_attribute?(attr_name) ⇒ Boolean
111 112 113 |
# File 'lib/reactor/cm/obj_class.rb', line 111 def has_attribute?(attr_name) attributes.include? attr_name end |
#mandatory_attributes ⇒ Object
123 124 125 |
# File 'lib/reactor/cm/obj_class.rb', line 123 def mandatory_attributes __attributes_get("mandatoryAttributes") end |
#mandatory_attributes=(attr_arr) ⇒ Object
127 128 129 |
# File 'lib/reactor/cm/obj_class.rb', line 127 def mandatory_attributes=(attr_arr) __attributes_set("mandatoryAttributes", attr_arr) end |
#preset(key, value) ⇒ Object
46 47 48 |
# File 'lib/reactor/cm/obj_class.rb', line 46 def preset(key, value) @preset[key] = value end |
#preset_attributes ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/reactor/cm/obj_class.rb', line 50 def preset_attributes request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, "name", @name) xml.get_key_tag!(base_name, "presetAttributes") end response = request.execute! result = response.xpath("//dictitem") result = [result] unless result.is_a?(Array) result.map do |dictitem| key = dictitem.children.detect { |c| c.name == "key" }.text raw_value = dictitem.children.detect { |c| c.name == "value" } value = if raw_value.children.detect { |c| c.is_a?(::REXML::Text) } raw_value.text else raw_value.children.map { |c| c.text } end { key => value } end.inject({}, &:merge) end |
#save! ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/reactor/cm/obj_class.rb', line 70 def save! request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, "name", @name) xml.set_tag!(base_name) do @params.each do |key, value| if [key][:cdata] xml.tag!(key.to_s) do xml.cdata!(value) end else xml.value_tag!(key.to_s, value) end end unless @preset.empty? preset_attributes.merge(@preset) xml.tag!("presetAttributes") do @preset.each do |key, value| xml.tag!("dictitem") do xml.tag!("key") do xml.text!(key.to_s) end xml.tag!("value") do if value.is_a?(Array) value.each do |item| xml.tag!("listitem") do xml.text!(item.to_s) end end else xml.text!(value.to_s) end end end end end end end end request.execute! end |
#set(key, value, options = {}) ⇒ Object
41 42 43 44 |
# File 'lib/reactor/cm/obj_class.rb', line 41 def set(key, value, = {}) [key.to_sym] = (!.nil? && !.empty? && ) || {} @params[key.to_sym] = value end |