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

new(options = {}) click to toggle source

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

Calls superclass method
# File lib/dbd/context.rb, line 19
def initialize(options = {})
  super
end

Public Instance Methods

<<(context_fact_collection) click to toggle source

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

Calls superclass method
# File lib/dbd/context.rb, line 35
def <<(context_fact_collection)
  super
end

Private Instance Methods

assert_fact_or_context_fact(context_fact) click to toggle source

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
context_subject() click to toggle source

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
set_context_subject(options) click to toggle source
# 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
set_fact_context_subject!(context_fact) click to toggle source

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_context_subject() click to toggle source

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