Class: Cobbler::Base
- Inherits:
-
Object
- Object
- Cobbler::Base
- Includes:
- Common::Debug, Common::Finders, Common::Lifecycle, Connection::Common, Connection::Handling
- Defined in:
- lib/cobbler/base.rb
Instance Method Summary collapse
-
#initialize(defs = {}, new_record = true) ⇒ Base
constructor
A new instance of Base.
-
#remove ⇒ Object
delete the item on the cobbler server.
-
#save ⇒ Object
Save an item on the remote cobbler server This will first lookup if the item already exists on the remote server and use its handle store the attributes.
Methods included from Common::Finders
Methods included from Common::Lifecycle
#api_methods, #cobbler_collections_store_callbacks, #cobbler_record_fields, #definitions, included, #locked_fields, #user_definitions
Methods included from Connection::Common
Methods included from Connection::Handling
Methods included from Common::Debug
Constructor Details
#initialize(defs = {}, new_record = true) ⇒ Base
Returns a new instance of Base.
74 75 76 77 78 79 80 |
# File 'lib/cobbler/base.rb', line 74 def initialize(defs = {},new_record = true) if new_record @user_definitions = defs else @definitions = defs end end |
Instance Method Details
#remove ⇒ Object
delete the item on the cobbler server
121 122 123 124 125 126 |
# File 'lib/cobbler/base.rb', line 121 def remove raise "Not all necessary api methods are defined to process this action!" unless api_methods[:remove] self.class.in_transaction(true) do |token| self.class.make_call(api_methods[:remove],name,token) end end |
#save ⇒ Object
Save an item on the remote cobbler server This will first lookup if the item already exists on the remote server and use its handle store the attributes. Otherwise a new item is created.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/cobbler/base.rb', line 92 def save unless [ :handle, :new, :modify, :save ].all?{|method| api_methods[method] } raise "Not all necessary api methods are defined to process this action!" end entry = self.class.find_one(name) self.class.in_transaction(true) do |token| if entry entryid = self.class.make_call(api_methods[:handle],name,token) else entryid = self.class.make_call(api_methods[:new],token) self.class.make_call(api_methods[:modify],entryid,'name', name, token) end cobbler_record_fields.each do |field| field_s = field.to_s if !locked_fields.include?(field) && user_definitions.has_key?(field_s) self.class.make_call(api_methods[:modify],entryid,field_s, user_definitions[field_s], token) end end cobbler_collections_store_callbacks.each do |callback| send(callback,entryid,token) end self.class.make_call(api_methods[:save],entryid,token) end end |