Class: Imaginary::Validators::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/imaginary/validators/option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, key) ⇒ Option

Returns a new instance of Option.



9
10
11
12
13
14
# File 'lib/imaginary/validators/option.rb', line 9

def initialize(type, key)
  raise 'Invalid Validator Option Type' unless %i[and or].include? type

  self.type = type
  self.key = key
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



7
8
9
# File 'lib/imaginary/validators/option.rb', line 7

def key
  @key
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/imaginary/validators/option.rb', line 6

def type
  @type
end

Instance Method Details

#append(result, object) ⇒ Object



16
17
18
19
20
# File 'lib/imaginary/validators/option.rb', line 16

def append(result, object)
  return (result && object.include?(key)) if type == :and

  result || object.include?(key)
end