module Cropio::Resource::Attributes
Defines accessors for resource attrubutes.
Public Class Methods
included(base)
click to toggle source
# File lib/cropio/resource/attributes.rb, line 5 def self.included(base) base.send(:attr_accessor, :attributes) end
Protected Instance Methods
attribute_defined?(attribute_name)
click to toggle source
# File lib/cropio/resource/attributes.rb, line 29 def attribute_defined?(attribute_name) @defined_attr ||= {} @defined_attr[attribute_name] ||= false end
attributes()
click to toggle source
# File lib/cropio/resource/attributes.rb, line 11 def attributes @attributes ||= {} end
attributes=(val)
click to toggle source
# File lib/cropio/resource/attributes.rb, line 15 def attributes=(val) @attributes = val end
define_attribute_getter(attribute_name)
click to toggle source
# File lib/cropio/resource/attributes.rb, line 39 def define_attribute_getter(attribute_name) instance_eval " def #{attribute_name} attributes['#{attribute_name}'] end " end
define_attribute_question(attribute_name)
click to toggle source
# File lib/cropio/resource/attributes.rb, line 55 def define_attribute_question(attribute_name) instance_eval " def #{attribute_name}? !attributes['#{attribute_name}'].nil? end " end
define_attribute_setter(attribute_name)
click to toggle source
# File lib/cropio/resource/attributes.rb, line 47 def define_attribute_setter(attribute_name) instance_eval " def #{attribute_name}=(val) attributes['#{attribute_name}'] = val end " end
define_attributes_accessors()
click to toggle source
# File lib/cropio/resource/attributes.rb, line 19 def define_attributes_accessors attributes.each_key do |attribute_name| next if attribute_defined?(attribute_name) define_attribute_getter(attribute_name) define_attribute_setter(attribute_name) define_attribute_question(attribute_name) defined!(attribute_name) end end
defined!(attribute_name)
click to toggle source
# File lib/cropio/resource/attributes.rb, line 34 def defined!(attribute_name) @defined_attr ||= {} @defined_attr[attribute_name] = true end
method_missing(name, *attrs, &block)
click to toggle source
Calls superclass method
# File lib/cropio/resource/attributes.rb, line 63 def method_missing(name, *attrs, &block) name = name.to_s attr_name = name.delete('=') if attributes.key?(attr_name) define_attributes_accessors name == attr_name ? send(name) : send(name, attrs.first) else super end end