Module: Representable::ClassMethods::Declarations
- Defined in:
- lib/representable.rb
Instance Method Summary collapse
-
#collection(name, options = {}, &block) ⇒ Object
Declares a represented document node collection.
- #hash(name = nil, options = {}) ⇒ Object
-
#property(name, options = {}, &block) ⇒ Object
Declares a represented document node, which is usually a XML tag or a JSON key.
- #representable_attrs ⇒ Object
- #representation_wrap=(name) ⇒ Object
Instance Method Details
#collection(name, options = {}, &block) ⇒ Object
Declares a represented document node collection.
Examples:
collection :products
collection :products, :from => :item
collection :products, :class => Product
130 131 132 133 |
# File 'lib/representable.rb', line 130 def collection(name, ={}, &block) [:collection] = true property(name, , &block) end |
#hash(name = nil, options = {}) ⇒ Object
135 136 137 138 139 140 |
# File 'lib/representable.rb', line 135 def hash(name=nil, ={}) return super() unless name # allow Object.hash. [:hash] = true property(name, ) end |
#property(name, options = {}, &block) ⇒ Object
Declares a represented document node, which is usually a XML tag or a JSON key.
Examples:
property :name
property :name, :from => :title
property :name, :class => Name
property :name, :default => "Mike"
property :name, :render_nil => true
property :name, :readable => false
property :name, :writeable => false
119 120 121 |
# File 'lib/representable.rb', line 119 def property(name, ={}, &block) representable_attrs << definition_class.new(name, ) end |
#representable_attrs ⇒ Object
100 101 102 |
# File 'lib/representable.rb', line 100 def representable_attrs @representable_attrs ||= build_config end |
#representation_wrap=(name) ⇒ Object
104 105 106 |
# File 'lib/representable.rb', line 104 def representation_wrap=(name) representable_attrs.wrap = name end |