class Reptar
Constants
- VERSION
Attributes
nodes[R]
Public Class Methods
attribute(name, options = {})
click to toggle source
# File lib/reptar.rb, line 31 def self.attribute(name, options = {}) @nodes[name] = options end
Also aliased as: collection
attributes(*attributes)
click to toggle source
# File lib/reptar.rb, line 35 def self.attributes(*attributes) attributes.each{ |e| @nodes[e] = nil } end
inherited(klass)
click to toggle source
# File lib/reptar.rb, line 27 def self.inherited(klass) klass.instance_variable_set("@nodes", {}) end
new(object)
click to toggle source
# File lib/reptar.rb, line 39 def initialize(object) @object = object end
Public Instance Methods
build_hash()
click to toggle source
# File lib/reptar.rb, line 57 def build_hash self.class.nodes.each_with_object({}) do |(name, options), hash| rep = options[:with] if options res = @object.respond_to?(name) ? @object.send(name) : self.send(name) res = Object.const_get(rep).new(res).representable if rep name = options[:key] if options && options[:key] hash[name] = res end end
method_missing(method_name)
click to toggle source
Calls superclass method
# File lib/reptar.rb, line 43 def method_missing(method_name) @object.respond_to?(method_name) ? @object.send(method_name) : super end
representable()
click to toggle source
# File lib/reptar.rb, line 52 def representable return nil unless @object @object.respond_to?(:to_a) ? @object.map{|e| self.class.new(e).build_hash } : build_hash end
to_json(options = {})
click to toggle source
# File lib/reptar.rb, line 47 def to_json(options = {}) root = options[:root] (root ? { root => representable } : representable).to_json end