Class: Reactor::Plans::CreateObj
- Inherits:
-
Object
- Object
- Reactor::Plans::CreateObj
- Defined in:
- lib/reactor/plans/create_obj.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ CreateObj
constructor
A new instance of CreateObj.
- #migrate! ⇒ Object
- #path ⇒ Object
- #prepare! ⇒ Object
- #set(key, value) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ CreateObj
Returns a new instance of CreateObj.
10 11 12 13 14 15 16 |
# File 'lib/reactor/plans/create_obj.rb', line 10 def initialize(opts={}) @name = opts[:name] @parent = opts[:parent] @objClass = opts[:objClass] @attrs = {} @ignoreExisting = opts[:ignoreExisting] end |
Instance Method Details
#migrate! ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/reactor/plans/create_obj.rb', line 33 def migrate! return true if (@ignoreExisting) && Reactor::Cm::Obj.exists?(path) @obj = Cm::Obj.create(@name, @parent, @objClass) @attrs.each do |key,value| @obj.set(key,value) end @obj.save! @obj.release! end |
#path ⇒ Object
43 44 45 |
# File 'lib/reactor/plans/create_obj.rb', line 43 def path File.join(@parent, @name) end |
#prepare! ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/reactor/plans/create_obj.rb', line 18 def prepare! raise "#{self.class.name}: name is nil" if @name.nil? raise "#{self.class.name}: parent is nil" if @parent.nil? raise "#{self.class.name}: objClass is nil" if @objClass.nil? raise "#{self.class.name}: parent does not exist" if not Reactor::Cm::Obj.exists?(@parent) raise "#{self.class.name}: obj with name #{@name} already exists" if (!@ignoreExisting) && Reactor::Cm::Obj.exists?(path) =begin raise "#{self.class.name}: objClass #{@objClass} not found" if not Reactor::Cm::ObjClass.exists?(@objClass) @attrs.keys.each do |attr| raise "#{self.class.name}: attr #{attr} not found for objClass #{@objClass}" if not Reactor::Cm::ObjClass.has_attribute?(attr) end =end # ...? end |
#set(key, value) ⇒ Object
6 7 8 |
# File 'lib/reactor/plans/create_obj.rb', line 6 def set(key, value) @attrs[key.to_sym] = value end |