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


133
134
135
136
# File 'lib/representable.rb', line 133

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

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



138
139
140
141
142
143
# File 'lib/representable.rb', line 138

def hash(name=nil, options={})
  return super() unless name  # allow Object.hash.

  options[:hash] = true
  property(name, options)
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


118
119
120
121
122
123
124
# File 'lib/representable.rb', line 118

def property(name, options={}, &block)
  if block_given? # DISCUSS: separate module?
    options[:extend] = inline_representer(representer_engine, &block)
  end

  (representable_attrs << definition_class.new(name, options)).last
end

#representable_attrsObject



99
100
101
# File 'lib/representable.rb', line 99

def representable_attrs
  @representable_attrs ||= build_config
end

#representation_wrap=(name) ⇒ Object



103
104
105
# File 'lib/representable.rb', line 103

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