Class: CastingAttrAccessor::Parser::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/casting_attr_accessor/parser/base.rb

Direct Known Subclasses

Array, Boolean, Date, DateTime, Fixnum, String, Symbol

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, attr, options = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
# File 'lib/casting_attr_accessor/parser/base.rb', line 7

def initialize(model, attr, options = {})
  @model = model
  @attribute = attr
  @options = options || {}
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



5
6
7
# File 'lib/casting_attr_accessor/parser/base.rb', line 5

def attribute
  @attribute
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/casting_attr_accessor/parser/base.rb', line 5

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/casting_attr_accessor/parser/base.rb', line 5

def options
  @options
end

Instance Method Details

#default_value(object) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/casting_attr_accessor/parser/base.rb', line 13

def default_value(object)
  default = options[:default]
  case default
    when Proc then default.call(object)
    else default
  end
end

#parse(value) ⇒ Object

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/casting_attr_accessor/parser/base.rb', line 21

def parse(value)
  raise NotImplementedError.new
end

#readersObject



29
30
31
# File 'lib/casting_attr_accessor/parser/base.rb', line 29

def readers
  [attribute]
end

#storage_varObject



25
26
27
# File 'lib/casting_attr_accessor/parser/base.rb', line 25

def storage_var
  :"@#{attribute}"
end

#writersObject



33
34
35
# File 'lib/casting_attr_accessor/parser/base.rb', line 33

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