module CurrencyCloud::Resource
Attributes
attributes[R]
changed_attributes[R]
Public Class Methods
included(base)
click to toggle source
# File lib/currency_cloud/resource.rb, line 7 def self.included(base) base.extend(ClassMethods) end
new(attributes)
click to toggle 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
inspect()
click to toggle 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
accessors=(attributes)
click to toggle 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
attributes=(new_values)
click to toggle source
# File lib/currency_cloud/resource.rb, line 31 def attributes=(new_values) @attributes = new_values.select { |k, _| valid_attributes.include?(k) } end
changed?()
click to toggle source
# File lib/currency_cloud/resource.rb, line 39 def changed? !@changed_attributes.empty? end
client()
click to toggle source
# File lib/currency_cloud/resource.rb, line 43 def client self.class.client end
metaclass()
click to toggle source
# File lib/currency_cloud/resource.rb, line 47 def metaclass class << self; self; end end
resource()
click to toggle source
# File lib/currency_cloud/resource.rb, line 27 def resource self.class.resource end
valid_attributes()
click to toggle source
# File lib/currency_cloud/resource.rb, line 35 def valid_attributes @attributes.keys end