Module: Windoo::Mixins::SoftwareTitle::ExtensionAttribute
- Included in:
- SoftwareTitle
- Defined in:
- lib/windoo/mixins/software_title/extension_attribute.rb
Overview
An module that manages the ExtensionAttribute in a SoftwareTitle.
Even though ‘extensionAttributes’ is plural, and they come from the server in an Array, at the moment there can only be one per SoftwareTitle.
This module hides that confusion and allows you to work with just one
If there’s already an extension attribute, you can access it from the #extensionAttribute getter, and use that to directly update its values.
Instance Method Summary collapse
-
#add_extensionAttribute(key:, displayName:, script:) ⇒ Integer
Add an ExtensionAttribute to this SoftwareTitle.
-
#delete_extensionAttribute ⇒ Integer
Delete the ExtensionAttribute from this SoftwareTitle.
-
#initialize(**init_data) ⇒ Object
Construcor.
Instance Method Details
#add_extensionAttribute(key:, displayName:, script:) ⇒ Integer
Add an ExtensionAttribute to this SoftwareTitle.
NOTE: There can be only one EA per SoftwareTitle. You will get an error if one already exists.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/windoo/mixins/software_title/extension_attribute.rb', line 65 def add_extensionAttribute(key:, displayName:, script:) if @extensionAttribute raise Windoo::AlreadyExistsError, 'This SoftwareTitle already has an Extension Attribute. Either delete it before creating a new one, or update the existing one.' end @extensionAttribute = Windoo::ExtensionAttribute.create( container: self, key: key, displayName: displayName, script: script ) @extensionAttribute.extensionAttributeId end |
#delete_extensionAttribute ⇒ Integer
Delete the ExtensionAttribute from this SoftwareTitle
When deleting an EA via this method, it is deleted from the server immediately, there is no need to #save the SoftwareTitle
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/windoo/mixins/software_title/extension_attribute.rb', line 89 def delete_extensionAttribute return unless @extensionAttribute deleted_id = @extensionAttribute.delete @extensionAttribute = nil deleted_id rescue Windoo::NoSuchItemError nil end |
#initialize(**init_data) ⇒ Object
Construcor
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/windoo/mixins/software_title/extension_attribute.rb', line 33 def initialize(**init_data) super @extensionAttribute = if @init_data[:extensionAttributes]&.first Windoo::ExtensionAttribute.instantiate_from_container( container: self, **@init_data[:extensionAttributes].first ) end end |