Class: ReactorSDK::Resources::LibraryWithResources

Inherits:
BaseResource
  • Object
show all
Defined in:
lib/reactor_sdk/resources/library_with_resources.rb

Instance Attribute Summary collapse

Attributes inherited from BaseResource

#attributes, #id, #meta, #relationships, #type

Instance Method Summary collapse

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.

Parameters:

  • id (String)

    Adobe library ID

  • type (String)

    JSON:API type (“libraries”)

  • attributes (Hash) (defaults to: {})

    Library attribute values

  • meta (Hash) (defaults to: {})

    Optional metadata

  • included_resources (Hash) (defaults to: {})

    Keyed by type — raw included resource arrays

    "rules"         => [ { "id" => "RL123", "type" => "rules",
                           "attributes" => {...,
                           "relationships" => { "latest_revision" => { "data" => { "id" => "RE123" } } } } ],
    "data_elements" => [ ... ],
    "extensions"    => [ ... ]
    

    }



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(meta),
    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_elementsArray<ReactorSDK::Resources::DataElement> (readonly)

Returns Data elements in this library Each data element has a revision_id attribute attached.

Returns:



60
61
62
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 60

def data_elements
  @data_elements
end

#extensionsArray<ReactorSDK::Resources::Extension> (readonly)

Returns Extensions in this library Each extension has a revision_id attribute attached.

Returns:



64
65
66
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 64

def extensions
  @extensions
end

#rulesArray<ReactorSDK::Resources::Rule> (readonly)

Returns Rules in this library Each rule has a revision_id attribute attached from the relationship data.

Returns:

  • (Array<ReactorSDK::Resources::Rule>)

    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_resourcesArray<BaseResource>

Returns all included resources as a flat array regardless of type.

Returns:



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.

Returns:

  • (Boolean)


113
114
115
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 113

def buildable?
  state == 'development'
end

#created_atString

Returns ISO8601 timestamp when the library was created.

Returns:

  • (String)

    ISO8601 timestamp when the library was created



46
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 46

attribute :created_at

#inspectString

Returns Human-readable representation.

Returns:

  • (String)

    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

#nameString

Returns Display name of the library.

Returns:

  • (String)

    Display name of the library



36
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 36

attribute :name

#publishedBoolean

Returns Whether the library has been published.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)


122
123
124
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 122

def published?
  state == 'published'
end

#published_atString?

Returns ISO8601 timestamp when the library was published.

Returns:

  • (String, nil)

    ISO8601 timestamp when the library was published



52
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 52

attribute :published_at

#resource_indexHash

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.

Returns:

  • (Hash)

    { “RL123” => “RE456”, “DE789” => “RE012”, … }



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

#stateString

Returns Current workflow state One of: “development”, “submitted”, “approved”, “rejected”, “published”.

Returns:

  • (String)

    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_atString

Returns ISO8601 timestamp when the library was last updated.

Returns:

  • (String)

    ISO8601 timestamp when the library was last updated



49
# File 'lib/reactor_sdk/resources/library_with_resources.rb', line 49

attribute :updated_at