Class: Representable::Definition
- Inherits:
-
Object
- Object
- Representable::Definition
- 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.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #array? ⇒ Boolean
- #attribute ⇒ Object
- #binding ⇒ Object
- #clone ⇒ Object
- #content ⇒ Object
- #create_binding(*args) ⇒ Object
- #default ⇒ Object
- #default_for(value) ⇒ Object
- #deserialize_class ⇒ Object
- #from ⇒ Object
- #has_default? ⇒ Boolean
- #hash? ⇒ Boolean
-
#initialize(sym, options = {}) ⇒ Definition
constructor
A new instance of Definition.
- #representer_module ⇒ Object
- #setter ⇒ Object
- #skipable_nil_value?(value) ⇒ Boolean
- #sync? ⇒ Boolean
- #typed? ⇒ Boolean
Constructor Details
#initialize(sym, options = {}) ⇒ Definition
Returns a new instance of Definition.
7 8 9 10 |
# File 'lib/representable/definition.rb', line 7 def initialize(sym, ={}) @name = sym.to_s = end |
Instance Attribute Details
#name ⇒ Object (readonly) Also known as: getter
Returns the value of attribute name.
4 5 6 |
# File 'lib/representable/definition.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/representable/definition.rb', line 4 def end |
Instance Method Details
#array? ⇒ Boolean
24 25 26 |
# File 'lib/representable/definition.rb', line 24 def array? [:collection] end |
#attribute ⇒ Object
54 55 56 |
# File 'lib/representable/definition.rb', line 54 def attribute [:attribute] end |
#binding ⇒ Object
70 71 72 |
# File 'lib/representable/definition.rb', line 70 def binding [:binding] end |
#clone ⇒ Object
12 13 14 |
# File 'lib/representable/definition.rb', line 12 def clone self.class.new(name, .clone) # DISCUSS: make generic Definition.cloned_attribute that passes list to constructor. end |
#content ⇒ Object
58 59 60 |
# File 'lib/representable/definition.rb', line 58 def content [:content] end |
#create_binding(*args) ⇒ Object
74 75 76 |
# File 'lib/representable/definition.rb', line 74 def create_binding(*args) binding.call(self, *args) end |
#default ⇒ Object
66 67 68 |
# File 'lib/representable/definition.rb', line 66 def default [:default] end |
#default_for(value) ⇒ Object
41 42 43 44 |
# File 'lib/representable/definition.rb', line 41 def default_for(value) return default if skipable_nil_value?(value) value end |
#deserialize_class ⇒ Object
32 33 34 |
# File 'lib/representable/definition.rb', line 32 def deserialize_class [:class] end |
#from ⇒ Object
36 37 38 39 |
# File 'lib/representable/definition.rb', line 36 def from # TODO: deprecate :from. ([:from] || [:as] || name).to_s end |
#has_default? ⇒ Boolean
46 47 48 |
# File 'lib/representable/definition.rb', line 46 def has_default? .has_key?(:default) end |
#hash? ⇒ Boolean
28 29 30 |
# File 'lib/representable/definition.rb', line 28 def hash? [:hash] end |
#representer_module ⇒ Object
50 51 52 |
# File 'lib/representable/definition.rb', line 50 def representer_module [:extend] or [:decorator] end |
#setter ⇒ Object
16 17 18 |
# File 'lib/representable/definition.rb', line 16 def setter :"#{name}=" end |
#skipable_nil_value?(value) ⇒ Boolean
62 63 64 |
# File 'lib/representable/definition.rb', line 62 def skipable_nil_value?(value) value.nil? and not [:render_nil] end |
#sync? ⇒ Boolean
78 79 80 |
# File 'lib/representable/definition.rb', line 78 def sync? [:parse_strategy] == :sync end |
#typed? ⇒ Boolean
20 21 22 |
# File 'lib/representable/definition.rb', line 20 def typed? deserialize_class.is_a?(Class) or representer_module or [:instance] # also true if only :extend is set, for people who want solely rendering. end |