class Krikri::EntityBehavior

Base class for retrieval behaviors related to entities that were generated or revised by a `Krikri::Activity`.

@example implementing an entity behavior

class CustomBehavior < Krikri::EntityBehavior
  def entities(load = true, include_invalidated = false)
    activity_uris(include_invalidated) do |uri|
      # some behavior over URIs to return initialized entities
    end
  end
end

@example retrieving entities with a behavior

Krikri::Activity.find(activity_id)
CustomBehavor.entities(activity)

A `SoftwareAgent` implements `#entity_behavior`, which returns an appropriate subclass of `EntityBehavior`. When an Activity is queried for its entities, it instantiates an instance of its particular `SoftwareAgent`, and then calls the `#entities` method of the agent's entity behavior.

@see Krikri::Activity#entities @see lib/krikri/entity_behaviors

Attributes

activity[R]

@!attribute [r] activity

@return [Krikri::Activity]

Public Class Methods

entities(activity, *args) click to toggle source

Initializes an instance of this class with the given `Activity` and returns an enumerator of the associated entities.

@param activity [Krikri::Activity] @param load [Boolean] @param include_invalidated [Boolean]

@see Krikri::EntityBehavior#entities @see Krikri::Activity#entities

# File lib/krikri/entity_behavior.rb, line 68
def self.entities(activity, *args)
  new(activity).entities(*args)
end
new(activity) click to toggle source

@param activity [Krikri::Activity]

# File lib/krikri/entity_behavior.rb, line 34
def initialize(activity)
  @activity = activity
end

Public Instance Methods

entities(*args) click to toggle source

Return an Enumerator of objects that have been affected by our @activity.

@param load [Boolean] `true` to force load the entities from the datastore

on access

@param include_invalidated [Boolean] `true` to include entities marked as

invalid.

@return [Enumerator] the entities. When possible, they should be

initialized & retrieved lazily.

@see lib/krikri/entity_behaviors @see Krikri::Activity#entities

@see Krikri::LDP::Invalidatable for more about “invalidated” entities

# File lib/krikri/entity_behavior.rb, line 54
def entities(*args)
  raise NotImplementedError
end

Private Instance Methods

activity_uris(include_invalidated, &block) click to toggle source

Private utility method capturing common logic for applying entity logic to uris gathered from the instance's `Krikri::Activity`.

@param include_invalided [Boolean]

@return [Enumerator::Lazy] the uris, lazily mapped to the behavior in the

given block
# File lib/krikri/entity_behavior.rb, line 82
def activity_uris(include_invalidated, &block)
  activity.entity_uris(include_invalidated).lazy.map(&block)
end