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
18 19 20 21 22 |
# File 'lib/reactor/cm/obj_class.rb', line 18 def self.create(name, type) klass = ObjClass.new klass.send(:create,name, type) klass end |
.exists?(name) ⇒ Boolean
9 10 11 12 13 14 15 16 |
# File 'lib/reactor/cm/obj_class.rb', line 9 def self.exists?(name) klass = ObjClass.new begin return klass.send(:get, name).ok? rescue return false end end |
.get(name) ⇒ Object
24 25 26 27 28 |
# File 'lib/reactor/cm/obj_class.rb', line 24 def self.get(name) klass = ObjClass.new klass.send(:get, name) klass end |
.rename(current_name, new_name) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/reactor/cm/obj_class.rb', line 30 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
104 105 106 |
# File 'lib/reactor/cm/obj_class.rb', line 104 def attributes __attributes_get('attributes') end |
#attributes=(attr_arr) ⇒ Object
108 109 110 |
# File 'lib/reactor/cm/obj_class.rb', line 108 def attributes=(attr_arr) __attributes_set('attributes', attr_arr) end |
#delete! ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/reactor/cm/obj_class.rb', line 120 def delete! request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, 'name', @name) xml.tag!("#{base_name}-delete") end response = request.execute! end |
#has_attribute?(attr_name) ⇒ Boolean
100 101 102 |
# File 'lib/reactor/cm/obj_class.rb', line 100 def has_attribute?(attr_name) attributes.include? attr_name end |
#mandatory_attributes ⇒ Object
112 113 114 |
# File 'lib/reactor/cm/obj_class.rb', line 112 def mandatory_attributes __attributes_get('mandatoryAttributes') end |
#mandatory_attributes=(attr_arr) ⇒ Object
116 117 118 |
# File 'lib/reactor/cm/obj_class.rb', line 116 def mandatory_attributes=(attr_arr) __attributes_set('mandatoryAttributes', attr_arr) end |
#preset(key, value) ⇒ Object
47 48 49 |
# File 'lib/reactor/cm/obj_class.rb', line 47 def preset(key, value) @preset[key] = value end |
#preset_attributes ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/reactor/cm/obj_class.rb', line 51 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.kind_of?(Array) result.map do |dictitem| key = dictitem.children.detect {|c| c.name == 'key'}.text value = dictitem.children.detect {|c| c.name == 'value'}.text {key => value} end.inject({}, &:merge) end |
#save! ⇒ Object
67 68 69 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 |
# File 'lib/reactor/cm/obj_class.rb', line 67 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 @params_options[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? all_preset = (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 xml.text!(value.to_s) end end end end end end end response = request.execute! end |
#set(key, value, options = {}) ⇒ Object
42 43 44 45 |
# File 'lib/reactor/cm/obj_class.rb', line 42 def set(key, value, ={}) @params_options[key.to_sym] = (!.nil? && !.empty? && ) || {} @params[key.to_sym] = value end |