Module: Qwack::BaseType

Includes:
Base
Included in:
Types::Boolean, Types::Date, Types::Email, Types::Float, Types::Integer, Types::String
Defined in:
lib/qwack/base_type.rb

Overview

Base module for user defined types

Instance Method Summary collapse

Methods included from Base

#mock!, #validate!

Instance Method Details

#mock(input = nil) ⇒ Object



38
39
40
# File 'lib/qwack/base_type.rb', line 38

def mock(input = nil)
  input || own_default_mock
end

#own_default_mockObject



24
25
26
27
28
# File 'lib/qwack/base_type.rb', line 24

def own_default_mock
  @own_default_mock = nil unless instance_variable_defined?('@own_default_mock')

  @own_default_mock
end

#own_validatorsObject



18
19
20
21
22
# File 'lib/qwack/base_type.rb', line 18

def own_validators
  @own_validators = [] unless instance_variable_defined?('@own_validators')

  @own_validators
end

#validation_errors(input, path = 'root') ⇒ Object



30
31
32
33
34
35
36
# File 'lib/qwack/base_type.rb', line 30

def validation_errors(input, path = 'root')
  validators.each_with_object([]) do |validator, errors|
    error = validator.call(input)
    errors << { path: path, name: name, desc: error, item: input } \
      unless error.nil?
  end
end

#validatorsObject



11
12
13
14
15
16
# File 'lib/qwack/base_type.rb', line 11

def validators
  ancestors.reverse.each_with_object([]) do |ancestor, obj|
    obj.append(*ancestor.own_validators) \
      if ancestor.respond_to?(:own_validators)
  end
end