Class: Representable::Definition
- Inherits:
-
Hash
- Object
- Hash
- Representable::Definition
show all
- Defined in:
- lib/representable/definition.rb
Overview
Created at class compile time. Keeps configuration options for one property.
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #getter)
readonly
Returns the value of attribute name.
Instance Method Summary
collapse
Methods included from Hash
#from_hash, included, #to_hash
Constructor Details
#initialize(sym, options = {}) ⇒ Definition
Returns a new instance of Definition.
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/representable/definition.rb', line 10
def initialize(sym, options={})
super()
options = options.clone
handle_deprecations!(options)
@name = sym.to_s
options[:as] ||= @name
setup!(options)
end
|
Instance Attribute Details
#name ⇒ Object
Also known as:
getter
Returns the value of attribute name.
7
8
9
|
# File 'lib/representable/definition.rb', line 7
def name
@name
end
|
Instance Method Details
#array? ⇒ Boolean
49
50
51
|
# File 'lib/representable/definition.rb', line 49
def array?
self[:collection]
end
|
#create_binding(*args) ⇒ Object
76
77
78
|
# File 'lib/representable/definition.rb', line 76
def create_binding(*args)
self[:binding].call(self, *args)
end
|
#default_for(value) ⇒ Object
57
58
59
60
|
# File 'lib/representable/definition.rb', line 57
def default_for(value)
return self[:default] if skipable_nil_value?(value)
value
end
|
#has_default? ⇒ Boolean
62
63
64
|
# File 'lib/representable/definition.rb', line 62
def has_default?
has_key?(:default)
end
|
#hash? ⇒ Boolean
53
54
55
|
# File 'lib/representable/definition.rb', line 53
def hash?
self[:hash]
end
|
#merge!(options) ⇒ Object
24
25
26
27
|
# File 'lib/representable/definition.rb', line 24
def merge!(options)
setup!(options)
self
end
|
#options ⇒ Object
31
32
33
34
|
# File 'lib/representable/definition.rb', line 31
def options warn "Representable::Definition#option is deprecated, use #[] directly."
self
end
|
#representable? ⇒ Boolean
44
45
46
47
|
# File 'lib/representable/definition.rb', line 44
def representable?
return if self[:representable] === false
self[:representable] or typed?
end
|
#representer_module ⇒ Object
66
67
68
|
# File 'lib/representable/definition.rb', line 66
def representer_module
self[:extend]
end
|
#setter ⇒ Object
36
37
38
|
# File 'lib/representable/definition.rb', line 36
def setter
:"#{name}="
end
|
#skipable_empty_value?(value) ⇒ Boolean
Also known as:
skipable_nil_value?
70
71
72
73
|
# File 'lib/representable/definition.rb', line 70
def skipable_empty_value?(value)
return true if array? and self[:render_empty] == false and value and value.size == 0 value.nil? and not self[:render_nil]
end
|
#typed? ⇒ Boolean
40
41
42
|
# File 'lib/representable/definition.rb', line 40
def typed?
self[:class] or self[:extend] or self[:instance]
end
|