Class: CastingAttributes::TypeCaster::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/casting_attributes/type_caster/base.rb

Direct Known Subclasses

Boolean, Fixnum, Float, String

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, attr) ⇒ Base

Returns a new instance of Base.



7
8
9
10
# File 'lib/casting_attributes/type_caster/base.rb', line 7

def initialize(model, attr)
  @model = model
  @attribute = attr
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



5
6
7
# File 'lib/casting_attributes/type_caster/base.rb', line 5

def attribute
  @attribute
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/casting_attributes/type_caster/base.rb', line 5

def model
  @model
end

Instance Method Details

#readersObject



16
17
18
# File 'lib/casting_attributes/type_caster/base.rb', line 16

def readers
  [attribute]
end

#storage_varObject



12
13
14
# File 'lib/casting_attributes/type_caster/base.rb', line 12

def storage_var
  :"@#{attribute}"
end

#typecast(value) ⇒ Object

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/casting_attributes/type_caster/base.rb', line 24

def typecast(value)
  raise NotImplementedError.new
end

#writersObject



20
21
22
# File 'lib/casting_attributes/type_caster/base.rb', line 20

def writers
  [:"#{attribute}="]
end