Class: Krikri::EntityBehavior

Inherits:
Object
  • Object
show all
Defined in:
lib/krikri/entity_behavior.rb

Overview

Base class for retrieval behaviors related to entities that were generated or revised by a ‘Krikri::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.

Examples:

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

retrieving entities with a behavior

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

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(activity) ⇒ EntityBehavior

Returns a new instance of EntityBehavior.

Parameters:



34
35
36
# File 'lib/krikri/entity_behavior.rb', line 34

def initialize(activity)
  @activity = activity
end

Instance Attribute Details

#activityObject (readonly)

Returns the value of attribute activity.



30
31
32
# File 'lib/krikri/entity_behavior.rb', line 30

def activity
  @activity
end

Class Method Details

.entities(activity, *args) ⇒ Object

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

Parameters:

See Also:



68
69
70
# File 'lib/krikri/entity_behavior.rb', line 68

def self.entities(activity, *args)
  new(activity).entities(*args)
end

Instance Method Details

#entities(*args) ⇒ Enumerator

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

Parameters:

  • load (Boolean)

    ‘true` to force load the entities from the datastore on access

  • include_invalidated (Boolean)

    ‘true` to include entities marked as invalid.

Returns:

  • (Enumerator)

    the entities. When possible, they should be initialized & retrieved lazily.

Raises:

  • (NotImplementedError)

See Also:



54
55
56
# File 'lib/krikri/entity_behavior.rb', line 54

def entities(*args)
  raise NotImplementedError
end