class Attributor::HashDSLCompiler::RequiresDSL

A class that encapsulates the available DSL under the ‘requires` keyword. In particular it allows to define requirements like: requires.all :attr1, :attr2, :attr3 requires.exclusive :attr1, :attr2, :attr3 requires.at_most(2).of :attr1, :attr2, :attr3 requires.at_least(2).of :attr1, :attr2, :attr3 requires.exactly(2).of :attr1, :attr2, :attr3 Note: all and exclusive can also use .of , it is equivalent

Attributes

options[RW]
target[RW]

Public Class Methods

new(target, **opts) click to toggle source
# File lib/attributor/hash_dsl_compiler.rb, line 87
def initialize(target, **opts)
  self.target = target
  self.options = opts
end

Public Instance Methods

all(*attr_names, **opts) click to toggle source
# File lib/attributor/hash_dsl_compiler.rb, line 92
def all(*attr_names, **opts)
  req = Requirement.new(**options.merge(opts).merge(all: attr_names))
  target.add_requirement req
  req
end
at_least(number) click to toggle source
# File lib/attributor/hash_dsl_compiler.rb, line 104
def at_least(number)
  req = Requirement.new(**options.merge(at_least: number))
  target.add_requirement req
  req
end
at_most(number) click to toggle source
# File lib/attributor/hash_dsl_compiler.rb, line 98
def at_most(number)
  req = Requirement.new(**options.merge(at_most: number))
  target.add_requirement req
  req
end
exactly(number) click to toggle source
# File lib/attributor/hash_dsl_compiler.rb, line 110
def exactly(number)
  req = Requirement.new(**options.merge(exactly: number))
  target.add_requirement req
  req
end
exclusive(*attr_names, **opts) click to toggle source
# File lib/attributor/hash_dsl_compiler.rb, line 116
def exclusive(*attr_names, **opts)
  req = Requirement.new(**options.merge(opts).merge(exclusive: attr_names))
  target.add_requirement req
  req
end