module OldApiResource::Attributes::ClassMethods
Public Instance Methods
attribute?(name)
click to toggle source
# File lib/old_api_resource/attributes.rb, line 89 def attribute?(name) self.attribute_names.include?(name.to_sym) end
clear_attributes()
click to toggle source
# File lib/old_api_resource/attributes.rb, line 97 def clear_attributes self.attribute_names.clear self.public_attribute_names.clear self.protected_attribute_names.clear end
define_attributes(*args)
click to toggle source
# File lib/old_api_resource/attributes.rb, line 35 def define_attributes(*args) # This is provided by ActiveModel::AttributeMethods, it should define the basic methods # but we need to override all the setters so we do dirty tracking define_attribute_methods args args.each do |arg| self.attribute_names << arg.to_sym self.public_attribute_names << arg.to_sym # Override the setter for dirty tracking self.class_eval <<-EOE, __FILE__, __LINE__ + 1 def #{arg} self.attributes[:#{arg}] end def #{arg}=(val) #{arg}_will_change! unless self.#{arg} == val self.attributes[:#{arg}] = val end def #{arg}? self.attributes[:#{arg}].present? end EOE end self.attribute_names.uniq! self.public_attribute_names.uniq! end
define_protected_attributes(*args)
click to toggle source
# File lib/old_api_resource/attributes.rb, line 63 def define_protected_attributes(*args) define_attribute_methods args args.each do |arg| self.attribute_names << arg.to_sym self.protected_attribute_names << arg.to_sym # These attributes cannot be set, throw an error if you try self.class_eval <<-EOE, __FILE__, __LINE__ + 1 def #{arg} self.attributes[:#{arg}] end def #{arg}=(val) raise "#{arg} is a protected attribute and cannot be set" end def #{arg}? self.attributes[:#{arg}].present? end EOE end self.attribute_names.uniq! self.protected_attribute_names.uniq! end
protected_attribute?(name)
click to toggle source
# File lib/old_api_resource/attributes.rb, line 93 def protected_attribute?(name) self.protected_attribute_names.include?(name.to_sym) end