Class: CastingAttrAccessor::Parser::Base
- Inherits:
-
Object
- Object
- CastingAttrAccessor::Parser::Base
show all
- Defined in:
- lib/casting_attr_accessor/parser/base.rb
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
#attribute ⇒ Object
Returns the value of attribute attribute.
5
6
7
|
# File 'lib/casting_attr_accessor/parser/base.rb', line 5
def attribute
@attribute
end
|
#model ⇒ Object
Returns the value of attribute model.
5
6
7
|
# File 'lib/casting_attr_accessor/parser/base.rb', line 5
def model
@model
end
|
#options ⇒ Object
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
21
22
23
|
# File 'lib/casting_attr_accessor/parser/base.rb', line 21
def parse(value)
raise NotImplementedError.new
end
|
#readers ⇒ Object
29
30
31
|
# File 'lib/casting_attr_accessor/parser/base.rb', line 29
def readers
[attribute]
end
|
#storage_var ⇒ Object
25
26
27
|
# File 'lib/casting_attr_accessor/parser/base.rb', line 25
def storage_var
:"@#{attribute}"
end
|
#writers ⇒ Object
33
34
35
|
# File 'lib/casting_attr_accessor/parser/base.rb', line 33
def writers
[:"#{attribute}="]
end
|