Class: InventoryRefresh::Target
- Inherits:
-
Object
- Object
- InventoryRefresh::Target
- Defined in:
- lib/inventory_refresh/target.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
-
#event_id ⇒ Object
readonly
Returns the value of attribute event_id.
-
#manager_ref ⇒ Object
(also: #name)
readonly
Returns the value of attribute manager_ref.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.dump(obj) ⇒ Hash
A Rails recommended interface for serializing an object.
-
.load(**args) ⇒ InventoryRefresh::Target
A Rails recommended interface for deserializing an object.
Instance Method Summary collapse
-
#dump ⇒ Hash
(also: #id)
Returns a serialized InventoryRefresh::Target object.
-
#initialize(association:, manager_ref:, manager: nil, manager_id: nil, event_id: nil, options: {}) ⇒ Target
constructor
A new instance of Target.
-
#load_from_db ⇒ ApplicationRecord
Loads InventoryRefresh::Target ApplicationRecord representation from our DB, this requires that InventoryRefresh::Target has been refreshed, otherwise the AR object can be missing.
-
#manager ⇒ ManageIQ::Providers::BaseManager
The Manager owning the Target.
-
#manager_id ⇒ Integer
A primary key of the Manager owning the Target.
Constructor Details
#initialize(association:, manager_ref:, manager: nil, manager_id: nil, event_id: nil, options: {}) ⇒ Target
Returns a new instance of Target.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/inventory_refresh/target.rb', line 13 def initialize(association:, manager_ref:, manager: nil, manager_id: nil, event_id: nil, options: {}) raise "Provide either :manager or :manager_id argument" if manager.nil? && manager_id.nil? @manager = manager @manager_id = manager_id @association = association @manager_ref = manager_ref @event_id = event_id @options = end |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
3 4 5 |
# File 'lib/inventory_refresh/target.rb', line 3 def association @association end |
#event_id ⇒ Object (readonly)
Returns the value of attribute event_id.
3 4 5 |
# File 'lib/inventory_refresh/target.rb', line 3 def event_id @event_id end |
#manager_ref ⇒ Object (readonly) Also known as: name
Returns the value of attribute manager_ref.
3 4 5 |
# File 'lib/inventory_refresh/target.rb', line 3 def manager_ref @manager_ref end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/inventory_refresh/target.rb', line 3 def @options end |
Class Method Details
.dump(obj) ⇒ Hash
A Rails recommended interface for serializing an object
34 35 36 |
# File 'lib/inventory_refresh/target.rb', line 34 def self.dump(obj) obj.dump end |
.load(**args) ⇒ InventoryRefresh::Target
A Rails recommended interface for deserializing an object
26 27 28 |
# File 'lib/inventory_refresh/target.rb', line 26 def self.load(**args) new(**args) end |
Instance Method Details
#dump ⇒ Hash Also known as: id
Returns a serialized InventoryRefresh::Target object. This can be used to initialize a new object, then the object target acts the same as the object InventoryRefresh::Target.new(target.serialize)
42 43 44 45 46 47 48 49 50 |
# File 'lib/inventory_refresh/target.rb', line 42 def dump { :manager_id => manager_id, :association => association, :manager_ref => manager_ref, :event_id => event_id, :options => } end |
#load_from_db ⇒ ApplicationRecord
Loads InventoryRefresh::Target ApplicationRecord representation from our DB, this requires that InventoryRefresh::Target has been refreshed, otherwise the AR object can be missing.
69 70 71 |
# File 'lib/inventory_refresh/target.rb', line 69 def load_from_db manager.public_send(association).find_by(manager_ref) end |
#manager ⇒ ManageIQ::Providers::BaseManager
Returns The Manager owning the Target.
56 57 58 |
# File 'lib/inventory_refresh/target.rb', line 56 def manager @manager || ManageIQ::Providers::BaseManager.find(@manager_id) end |
#manager_id ⇒ Integer
Returns A primary key of the Manager owning the Target.
61 62 63 |
# File 'lib/inventory_refresh/target.rb', line 61 def manager_id @manager_id || manager.try(:id) end |