Class: Inspector::Constraints::Valid

Inherits:
Object
  • Object
show all
Includes:
Inspector::Constraint
Defined in:
lib/inspector/constraints/valid.rb

Instance Method Summary collapse

Methods included from Inspector::Constraint

#negate!, #positive?

Constructor Details

#initialize(*args) ⇒ Valid

Returns a new instance of Valid.



6
7
8
9
10
11
# File 'lib/inspector/constraints/valid.rb', line 6

def initialize(*args)
  if args.length == 1
    @use_custom_type = true
    @type = args.first
  end
end

Instance Method Details

#inspectObject



26
27
28
# File 'lib/inspector/constraints/valid.rb', line 26

def inspect
  "#<valid%{type}>" % { :type => " #{@type}".rstrip }
end

#to_sObject



22
23
24
# File 'lib/inspector/constraints/valid.rb', line 22

def to_s
  "validate"
end

#validate_as(value) ⇒ Object



13
14
15
16
# File 'lib/inspector/constraints/valid.rb', line 13

def validate_as(value)
  return @type if @use_custom_type
  value.class
end

#validatorObject



18
19
20
# File 'lib/inspector/constraints/valid.rb', line 18

def validator
  :validity
end