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
8 9 10 11 12 13 14 |
# File 'lib/reactor/plans/create_obj.rb', line 8 def initialize(opts = {}) @name = opts[:name] @parent = opts[:parent] @objClass = opts[:objClass] @attrs = {} @ignoreExisting = opts[:ignoreExisting] end |
Instance Method Details
#migrate! ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/reactor/plans/create_obj.rb', line 31 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
42 43 44 |
# File 'lib/reactor/plans/create_obj.rb', line 42 def path File.join(@parent, @name) end |
#prepare! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/reactor/plans/create_obj.rb', line 16 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" unless Reactor::Cm::Obj.exists?(@parent) if !@ignoreExisting && Reactor::Cm::Obj.exists?(path) raise "#{self.class.name}: obj with name #{@name} already exists" end # 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 |
#set(key, value) ⇒ Object
4 5 6 |
# File 'lib/reactor/plans/create_obj.rb', line 4 def set(key, value) @attrs[key.to_sym] = value end |