Class: Compel::Validators::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/compel/validators/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, schema) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
16
# File 'lib/compel/validators/base.rb', line 11

def initialize(input, schema)
  @input = input.nil? ? schema.default_value : input
  @schema = schema
  @output = nil
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/compel/validators/base.rb', line 6

def errors
  @errors
end

#inputObject (readonly)

Returns the value of attribute input.



6
7
8
# File 'lib/compel/validators/base.rb', line 6

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



6
7
8
# File 'lib/compel/validators/base.rb', line 6

def output
  @output
end

#schemaObject (readonly)

Returns the value of attribute schema.



6
7
8
# File 'lib/compel/validators/base.rb', line 6

def schema
  @schema
end

Class Method Details

.validate(input, schema) ⇒ Object



22
23
24
# File 'lib/compel/validators/base.rb', line 22

def self.validate(input, schema)
  new(input, schema).validate
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/compel/validators/base.rb', line 18

def valid?
  @errors.empty?
end