class Shaf::Profile::Evaluator

Attributes

allowed[R]
parent[R]

Public Class Methods

new(parent:, allowed: nil) click to toggle source
# File lib/shaf/profile/evaluator.rb, line 11
def initialize(parent:, allowed: nil)
  @parent = parent
  @allowed = allowed && Array(allowed).map(&:to_sym)
end

Public Instance Methods

attribute(name, doc:, type: :string, &block) click to toggle source
# 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
rel(name, **kwargs, &block)
Alias for: relation
relation(name, **kwargs, &block) click to toggle source
# 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
Also aliased as: rel

Private Instance Methods

allow?(name) click to toggle source
# File lib/shaf/profile/evaluator.rb, line 35
def allow?(name)
  return true unless allowed
  return true if allowed.include? name

  Shaf.log.warn "#{name} is not allowed to be nested inside #{parent.class} " \
    "(or parent object containing #{parent.class})"

  false
end