Class: Mongomatic::TypeConverters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mongomatic/type_converters.rb

Direct Known Subclasses

Array, Bool, Fixnum, Float, Hash, ObjectId, Regex, String, Symbol, Time

Instance Method Summary collapse

Constructor Details

#initialize(orig_val) ⇒ Base

Returns a new instance of Base.



10
11
12
# File 'lib/mongomatic/type_converters.rb', line 10

def initialize(orig_val)
  @orig_val = orig_val
end

Instance Method Details

#castObject



18
19
20
21
22
23
24
# File 'lib/mongomatic/type_converters.rb', line 18

def cast
  if type_match?
    @orig_val
  else
    convert_orig_val || raise(CannotCastValue)
  end
end

#convert_orig_valObject



26
27
28
# File 'lib/mongomatic/type_converters.rb', line 26

def convert_orig_val
  raise "abstract"
end

#type_match?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/mongomatic/type_converters.rb', line 14

def type_match?
  raise "abstract"
end