Class: Compel::Coercion::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/compel/coercion/types/type.rb

Direct Known Subclasses

Array, Boolean, Date, DateTime, Float, Hash, Integer, JSON, Regexp, String, Time

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, options = {}) ⇒ Type

Returns a new instance of Type.



9
10
11
12
# File 'lib/compel/coercion/types/type.rb', line 9

def initialize(value, options = {})
  @value = value
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/compel/coercion/types/type.rb', line 6

def options
  @options
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/compel/coercion/types/type.rb', line 6

def value
  @value
end

Instance Method Details

#coerceObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/compel/coercion/types/type.rb', line 14

def coerce
  result = coerce_value

  # There are some special cases that
  # we need to build a custom error
  if result.is_a?(Result)
    return result
  end

  Result.new(result, value, self.class)
end