Module: Representable::ClassMethods::Declarations

Defined in:
lib/representable.rb

Instance Method Summary collapse

Instance Method Details

#definition_classObject



56
57
58
# File 'lib/representable.rb', line 56

def definition_class
  Definition
end

#representable_bindingsObject

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, options={})
  options[:collection] = true
  representable_property(name, options)
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, options={})
  attr = add_representable_property(name, options)
  
  attr_reader(attr.getter) unless options[:accessors] == false
  attr_writer(attr.getter) unless options[:accessors] == false
end