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
- #mock(input = nil) ⇒ Object
- #own_default_mock ⇒ Object
- #own_validators ⇒ Object
- #validation_errors(input, path = 'root') ⇒ Object
- #validators ⇒ Object
Methods included from Base
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_mock ⇒ Object
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_validators ⇒ Object
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 |
#validators ⇒ Object
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 |