Module: Representable::ClassMethods::Declarations

Defined in:
lib/representable.rb

Instance Method Summary collapse

Instance Method Details

#collection(name, options = {}) ⇒ Object

Declares a represented document node collection.

Examples:

collection :products
collection :products, :from => :item
collection :products, :class => Product


177
178
179
180
# File 'lib/representable.rb', line 177

def collection(name, options={})
  options[:collection] = true
  property(name, options)
end

#hash(name = nil, options = {}) ⇒ Object



182
183
184
185
186
187
# File 'lib/representable.rb', line 182

def hash(name=nil, options={})
  return super() unless name  # allow Object.hash.
  
  options[:hash] = true
  property(name, options)
end

#property(name, options = {}) ⇒ 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


166
167
168
# File 'lib/representable.rb', line 166

def property(name, options={})
  representable_attrs << definition_class.new(name, options)
end

#representable_attrsObject



149
150
151
# File 'lib/representable.rb', line 149

def representable_attrs
  @representable_attrs ||= Config.new
end

#representation_wrap=(name) ⇒ Object



153
154
155
# File 'lib/representable.rb', line 153

def representation_wrap=(name)
  representable_attrs.wrap = name
end