Class: ReactorSDK::Resources::LibraryWithResources
- Inherits:
-
BaseResource
- Object
- BaseResource
- ReactorSDK::Resources::LibraryWithResources
- Defined in:
- lib/reactor_sdk/resources/library_with_resources.rb
Instance Attribute Summary collapse
-
#data_elements ⇒ Array<ReactorSDK::Resources::DataElement>
readonly
Data elements in this library Each data element has a revision_id attribute attached.
-
#extensions ⇒ Array<ReactorSDK::Resources::Extension>
readonly
Extensions in this library Each extension has a revision_id attribute attached.
-
#rules ⇒ Array<ReactorSDK::Resources::Rule>
readonly
Rules in this library Each rule has a revision_id attribute attached from the relationship data.
Attributes inherited from BaseResource
#attributes, #id, #meta, #relationships, #type
Instance Method Summary collapse
-
#all_resources ⇒ Array<BaseResource>
Returns all included resources as a flat array regardless of type.
-
#buildable? ⇒ Boolean
Returns true if the library is in a state where it can be built.
-
#created_at ⇒ String
ISO8601 timestamp when the library was created.
-
#initialize(id:, type:, attributes: {}, meta: {}, relationships: {}, included_resources: {}) ⇒ LibraryWithResources
constructor
Initializes the library with its included resources.
-
#inspect ⇒ String
Human-readable representation.
-
#name ⇒ String
Display name of the library.
-
#published ⇒ Boolean
Whether the library has been published.
-
#published? ⇒ Boolean
Returns true if the library has been successfully published.
-
#published_at ⇒ String?
ISO8601 timestamp when the library was published.
-
#resource_index ⇒ Hash
Returns a flat index of all resources keyed by Adobe resource ID.
-
#state ⇒ String
Current workflow state One of: “development”, “submitted”, “approved”, “rejected”, “published”.
-
#updated_at ⇒ String
ISO8601 timestamp when the library was last updated.
Methods inherited from BaseResource
#==, #[], attribute, #relationship_data, #relationship_id, #relationship_ids, #to_h
Constructor Details
#initialize(id:, type:, attributes: {}, meta: {}, relationships: {}, included_resources: {}) ⇒ LibraryWithResources
Initializes the library with its included resources.
Accepts the standard BaseResource arguments plus an included_resources hash that maps resource type to arrays of raw JSON:API resource hashes extracted from the API response included array.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 86 def initialize( id:, type:, attributes: {}, meta: {}, relationships: {}, included_resources: {} ) super( id: id, type: type, attributes: normalize_value(attributes), meta: normalize_value(), relationships: normalize_value(relationships) ) normalized_included_resources = normalize_value(included_resources) @rules = build_resources(resource_group(normalized_included_resources, 'rules'), Resources::Rule) @data_elements = build_resources(resource_group(normalized_included_resources, 'data_elements'), Resources::DataElement) @extensions = build_resources(resource_group(normalized_included_resources, 'extensions'), Resources::Extension) end |
Instance Attribute Details
#data_elements ⇒ Array<ReactorSDK::Resources::DataElement> (readonly)
Returns Data elements in this library Each data element has a revision_id attribute attached.
60 61 62 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 60 def data_elements @data_elements end |
#extensions ⇒ Array<ReactorSDK::Resources::Extension> (readonly)
Returns Extensions in this library Each extension has a revision_id attribute attached.
64 65 66 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 64 def extensions @extensions end |
#rules ⇒ Array<ReactorSDK::Resources::Rule> (readonly)
Returns Rules in this library Each rule has a revision_id attribute attached from the relationship data.
56 57 58 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 56 def rules @rules end |
Instance Method Details
#all_resources ⇒ Array<BaseResource>
Returns all included resources as a flat array regardless of type.
148 149 150 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 148 def all_resources @rules + @data_elements + @extensions end |
#buildable? ⇒ Boolean
Returns true if the library is in a state where it can be built.
113 114 115 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 113 def buildable? state == 'development' end |
#created_at ⇒ String
Returns ISO8601 timestamp when the library was created.
46 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 46 attribute :created_at |
#inspect ⇒ String
Returns Human-readable representation.
155 156 157 158 159 160 161 162 163 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 155 def inspect '#<ReactorSDK::Resources::LibraryWithResources ' \ "id=#{id.inspect} " \ "name=#{name.inspect} " \ "state=#{state.inspect} " \ "rules=#{@rules.length} " \ "data_elements=#{@data_elements.length} " \ "extensions=#{@extensions.length}>" end |
#name ⇒ String
Returns Display name of the library.
36 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 36 attribute :name |
#published ⇒ Boolean
Returns Whether the library has been published.
43 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 43 attribute :published, as: :boolean |
#published? ⇒ Boolean
Returns true if the library has been successfully published.
122 123 124 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 122 def published? state == 'published' end |
#published_at ⇒ String?
Returns ISO8601 timestamp when the library was published.
52 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 52 attribute :published_at |
#resource_index ⇒ Hash
Returns a flat index of all resources keyed by Adobe resource ID. Maps each resource ID to its current revision ID. Covers rules, data elements, and extensions in a single lookup.
Used by the app to compare two libraries — call resource_index on both the source and target library, then compare revision IDs to find what changed, what was added, and what needs upstream resolution.
137 138 139 140 141 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 137 def resource_index (@rules + @data_elements + @extensions).each_with_object({}) do |resource, index| index[resource.id] = resource.revision_id if resource.revision_id end end |
#state ⇒ String
Returns Current workflow state One of: “development”, “submitted”, “approved”, “rejected”, “published”.
40 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 40 attribute :state |
#updated_at ⇒ String
Returns ISO8601 timestamp when the library was last updated.
49 |
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 49 attribute :updated_at |