Class: ClassyHash::Generate::Composite

Inherits:
Object
  • Object
show all
Defined in:
lib/classy_hash/generate.rb

Overview

Used by the .all and .not generators. Do not use directly.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(constraints, negate = false) ⇒ Composite

Initializes a composite constraint with the given Array of constraints. If negate is true, then the constraints must all fail for the value to pass.



21
22
23
24
25
26
# File 'lib/classy_hash/generate.rb', line 21

def initialize(constraints, negate = false)
  raise 'No constraints were given' if constraints.empty?

  @constraints = constraints
  @negate = negate
end

Instance Attribute Details

#constraintsObject (readonly)

Array of constraints to apply together.



12
13
14
# File 'lib/classy_hash/generate.rb', line 12

def constraints
  @constraints
end

#negateObject (readonly)

True if the constraints must all not match, false if they must all match.



16
17
18
# File 'lib/classy_hash/generate.rb', line 16

def negate
  @negate
end

Instance Method Details

#describe(value) ⇒ Object

Returns a String describing the composite constraint failing against the given value.



30
31
32
# File 'lib/classy_hash/generate.rb', line 30

def describe(value)
  "#{negate ? 'none' : 'all'} of [#{CH.constraint_string(constraints, value)}]"
end