Module: Krikri::EntityConsumer
- Extended by:
- ActiveSupport::Concern
- Included in:
- Enricher, Indexer, Mapper::Agent
- Defined in:
- lib/krikri/entity_consumer.rb
Overview
A mixin for ‘Krikri::SoftwareAgent`s that use entities. Provides a mechanism for setting an `#entity_source` and consuming entities.
For backwards compatability, this supports an older interface where entities are selected based on a ‘generator_activity`.
Instance Method Summary collapse
-
#assign_generator_activity!(opts) ⇒ Object
Store this agent’s generator activity, which is the activity that produced the target entities upon which the current agent will operate.
-
#entities ⇒ Enumerator<Krikri::LDP::Resource>
Entities this agent will use.
- #entity_source ⇒ #entities?
-
#set_entity_source!(klass, *args, &block) ⇒ void
Sets the entity source to a new instance of the provided class, initialized with the provided arguments and block.
Instance Method Details
#assign_generator_activity!(opts) ⇒ Object
Store this agent’s generator activity, which is the activity that produced the target entities upon which the current agent will operate.
It is assumed that the agent class will define #entity_behavior, which returns the class of the appropriate behavior.
‘generator_uri’ can be a string or RDF::URI.
In the future, we might want to take a ‘generator_activity’ parameter, because not every activity will modify its entities with provenance messages; an indexing activity, in particular. In this case an LDP URI representing the activity is not relevant.
41 42 43 44 45 46 47 |
# File 'lib/krikri/entity_consumer.rb', line 41 def assign_generator_activity!(opts) if opts.include?(:generator_uri) generator_uri = opts.delete(:generator_uri) @entity_source = @generator_activity = Krikri::Activity.from_uri(generator_uri) end end |
#entities ⇒ Enumerator<Krikri::LDP::Resource>
Returns entities this agent will use.
51 52 53 |
# File 'lib/krikri/entity_consumer.rb', line 51 def entities entity_source ? entity_source.entities : [] end |
#entity_source ⇒ #entities?
57 58 59 |
# File 'lib/krikri/entity_consumer.rb', line 57 def entity_source @entity_source end |
#set_entity_source!(klass, *args, &block) ⇒ void
This method returns an undefined value.
Sets the entity source to a new instance of the provided class, initialized with the provided arguments and block.
67 68 69 |
# File 'lib/krikri/entity_consumer.rb', line 67 def set_entity_source!(klass, *args, &block) @entity_source = klass.new(*args, &block) end |