Class: Shaf::Profile::Evaluator
- Inherits:
-
Object
- Object
- Shaf::Profile::Evaluator
- Defined in:
- lib/shaf/profile/evaluator.rb
Instance Attribute Summary collapse
-
#allowed ⇒ Object
readonly
Returns the value of attribute allowed.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #attribute(name, doc:, type: :string, &block) ⇒ Object
-
#initialize(parent:, allowed: nil) ⇒ Evaluator
constructor
A new instance of Evaluator.
- #relation(name, **kwargs, &block) ⇒ Object (also: #rel)
Constructor Details
#initialize(parent:, allowed: nil) ⇒ Evaluator
Returns a new instance of Evaluator.
11 12 13 14 |
# File 'lib/shaf/profile/evaluator.rb', line 11 def initialize(parent:, allowed: nil) @parent = parent @allowed = allowed && Array(allowed).map(&:to_sym) end |
Instance Attribute Details
#allowed ⇒ Object (readonly)
Returns the value of attribute allowed.
9 10 11 |
# File 'lib/shaf/profile/evaluator.rb', line 9 def allowed @allowed end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
9 10 11 |
# File 'lib/shaf/profile/evaluator.rb', line 9 def parent @parent end |
Instance Method Details
#attribute(name, doc:, type: :string, &block) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/shaf/profile/evaluator.rb', line 16 def attribute(name, doc:, type: :string, &block) return unless allow? :attribute attr = Attribute.new(name, doc: doc, type: type, parent: parent) self.class.new(parent: attr, allowed: allowed).instance_exec(&block) if block parent.attributes << attr end |
#relation(name, **kwargs, &block) ⇒ Object Also known as: rel
24 25 26 27 28 29 30 |
# File 'lib/shaf/profile/evaluator.rb', line 24 def relation(name, **kwargs, &block) return unless allow? :rel rel = Relation.new(name, parent: parent, **kwargs) self.class.new(parent: rel, allowed: [:attribute]).instance_exec(&block) if block parent.relations << rel end |