module CurrencyCloud::Resource
Attributes
Public Class Methods
Source
# File lib/currency_cloud/resource.rb, line 7 def self.included(base) base.extend(ClassMethods) end
Source
# File lib/currency_cloud/resource.rb, line 13 def initialize(attributes) @attributes = attributes @changed_attributes = Set.new self.accessors = valid_attributes end
Public Instance Methods
Source
# File lib/currency_cloud/resource.rb, line 19 def inspect "#<#{self.class}:0x#{object_id.to_s(16)} #{@attributes.inspect}>" end
Private Instance Methods
Source
# File lib/currency_cloud/resource.rb, line 51 def accessors=(attributes) metaclass.instance_eval do attributes.each do |attribute| define_method(attribute) { @attributes[attribute] } define_method("#{attribute}=".to_sym) do |value| @attributes[attribute] = value @changed_attributes << attribute end end end end
Source
# File lib/currency_cloud/resource.rb, line 31 def attributes=(new_values) @attributes = new_values.select { |k, _| valid_attributes.include?(k) } end
Source
# File lib/currency_cloud/resource.rb, line 39 def changed? !@changed_attributes.empty? end
Source
# File lib/currency_cloud/resource.rb, line 47 def metaclass class << self; self; end end
Source
# File lib/currency_cloud/resource.rb, line 27 def resource self.class.resource end
Source
# File lib/currency_cloud/resource.rb, line 35 def valid_attributes @attributes.keys end