class Dbd::Context
A Context
is derived from a Resource
, and is the set of all ContextFacts that share the same subject.
It is pointed to by a context_subject
of a Fact
and has no context_subject
itself (the context_subject
relationship from Fact
to ContextFact
is not recursive).
Public Class Methods
Build a new Context
.
The subject can be either given as an argument or a new (random) subject is automatically set (see Resource
for details).
A context_subject
may not be given here. @option options [Fact::Subject] :subject (new_subject) Optional: the subject for the resource
# File lib/dbd/context.rb, line 19 def initialize(options = {}) super end
Public Instance Methods
Add a ContextFact
(strictly only a ContextFact
) or recursive collection of ContextFacts
Side effect on the context_fact argument:
-
if it has no subject, the subject is set in the context_fact
-
if is has the same subject as the resource, added unchanged.
-
if it has a different subject, a
SubjectError
is raised.
NOTE: this implementation is really only here for the documentation
@param [ContextFact, each] context_fact_collection a recursive collection of ContextFacts @return [Context] self
# File lib/dbd/context.rb, line 35 def <<(context_fact_collection) super end
Private Instance Methods
Assert only Contexts here
# File lib/dbd/context.rb, line 58 def assert_fact_or_context_fact(context_fact) raise ArgumentError, "Trying to add a non-ContextFact to a Context." unless context_fact.context_fact? end
Should not be called in Context
subclass.
# File lib/dbd/context.rb, line 42 def context_subject raise NoMethodError, "context_subject should not be called in Context." end
# File lib/dbd/context.rb, line 46 def set_context_subject(options) raise ArgumentError, "context_subject must not be in the options" if options[:context_subject] end
A noop for Context
. @param [ContextFact] context_fact
# File lib/dbd/context.rb, line 65 def set_fact_context_subject!(context_fact) # Do nothing end
Validate that context_subject
is not present here. This should never raise as the setter was blocked above.
# File lib/dbd/context.rb, line 52 def validate_context_subject raise ContextError if @context_subject end