Module: Mugatu::AttributeType

Included in:
Array, Boolean, Float, Hash, Integer, String
Defined in:
lib/mugatu/attribute_type.rb

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/mugatu/attribute_type.rb', line 11

def cast(value)
  if value.respond_to?(get_cast_with)
    value.send(get_cast_with)
  else
    raise_cast_error(value)
  end
end

#get_cast_withObject



7
8
9
# File 'lib/mugatu/attribute_type.rb', line 7

def get_cast_with
  @cast_with
end

#raise_cast_error(value) ⇒ Object

Raises:

  • (TypeError)


19
20
21
# File 'lib/mugatu/attribute_type.rb', line 19

def raise_cast_error(value)
  raise TypeError, "cannot cast #{value} into #{name} (TypeError)"
end

#set_cast_with(sym) ⇒ Object



3
4
5
# File 'lib/mugatu/attribute_type.rb', line 3

def set_cast_with(sym)
  @cast_with = sym
end