Module: Representable::ClassMethods::Declarations
- Defined in:
- lib/representable.rb
Instance Method Summary collapse
- #definition_class ⇒ Object
-
#representable_bindings ⇒ Object
Returns bindings for all properties.
-
#representable_collection(name, options = {}) ⇒ Object
Declares a represented document node collection.
-
#representable_property(name, options = {}) ⇒ Object
Declares a represented document node, which is usually a XML tag or a JSON key.
Instance Method Details
#definition_class ⇒ Object
56 57 58 |
# File 'lib/representable.rb', line 56 def definition_class Definition end |
#representable_bindings ⇒ Object
Returns bindings for all properties.
61 62 63 |
# File 'lib/representable.rb', line 61 def representable_bindings representable_attrs.map {|attr| binding_for_definition(attr) } end |
#representable_collection(name, options = {}) ⇒ Object
Declares a represented document node collection.
Examples:
representable_collection :products
representable_collection :products, :from => :item
representable_collection :products, :as => Product
88 89 90 91 |
# File 'lib/representable.rb', line 88 def representable_collection(name, ={}) [:collection] = true representable_property(name, ) end |
#representable_property(name, options = {}) ⇒ Object
Declares a represented document node, which is usually a XML tag or a JSON key.
Examples:
representable_property :name
representable_property :name, :from => :title
representable_property :name, :as => Name
representable_property :name, :accessors => false
representable_property :name, :default => "Mike"
74 75 76 77 78 79 |
# File 'lib/representable.rb', line 74 def representable_property(name, ={}) attr = add_representable_property(name, ) attr_reader(attr.getter) unless [:accessors] == false attr_writer(attr.getter) unless [:accessors] == false end |