class Nagare::Item
Attributes
context[R]
object[R]
Public Class Methods
_attributes()
click to toggle source
# File lib/nagare.rb, line 6 def self._attributes @attributes ||= [] end
_options()
click to toggle source
# File lib/nagare.rb, line 30 def self._options @options ||= {} end
attributes(*attributes)
click to toggle source
# File lib/nagare.rb, line 10 def self.attributes(*attributes) @attributes = _attributes.concat(attributes) attributes.each do |attribute| define_method(attribute) do if object.respond_to?(attribute) object.send(attribute) elsif context.respond_to?(attribute) context.send(attribute) end end end end
inherited(base)
click to toggle source
Calls superclass method
# File lib/nagare.rb, line 24 def self.inherited(base) base.instance_variable_set(:@attributes, @attributes.dup) if @attributes super end
new(object, context)
click to toggle source
# File lib/nagare.rb, line 38 def initialize(object, context) @object = object @context = context end
options(options)
click to toggle source
# File lib/nagare.rb, line 34 def self.options(options) @options = options end
Public Instance Methods
as_json(options = nil)
click to toggle source
# File lib/nagare.rb, line 64 def as_json(options = nil) attributes end
attributes()
click to toggle source
# File lib/nagare.rb, line 43 def attributes attributes = self.class._attributes.inject({}) do |hash, attribute| hash[attribute.to_s] = send(attribute) hash end if !self.class._options.fetch(:nil, false) attributes.compact else attributes end end
method_missing(key, *args)
click to toggle source
Calls superclass method
# File lib/nagare.rb, line 56 def method_missing(key, *args) if context.respond_to?(key) context.send(key, *args) else super end end