Module: ApiResource::Attributes::InstanceMethods

Defined in:
lib/api_resource/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute?(name) ⇒ Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/api_resource/attributes.rb', line 132

def attribute?(name)
  self.class.attribute?(name)
end

#protected_attribute?(name) ⇒ Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/api_resource/attributes.rb', line 136

def protected_attribute?(name)
  self.class.protected_attribute?(name)
end

#reset_attribute_changes(*attrs) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/api_resource/attributes.rb', line 123

def reset_attribute_changes(*attrs)
  attrs = self.class.public_attribute_names if attrs.blank?
  attrs.each do |attr|
    self.send("reset_#{attr}!")
  end
  
  set_attributes_as_current(*attrs)
end

#respond_to?(sym) ⇒ Boolean

Returns:

  • (Boolean)


140
141
142
143
144
145
146
147
148
149
# File 'lib/api_resource/attributes.rb', line 140

def respond_to?(sym)
  if sym =~ /\?$/
    return true if self.attribute?($`)
  elsif sym =~ /=$/
    return true if self.class.public_attribute_names.include?($`)
  else
    return true if self.attribute?(sym.to_sym)
  end
  super
end

#save_with_dirty_tracking(*args) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/api_resource/attributes.rb', line 106

def save_with_dirty_tracking(*args)
  if save_without_dirty_tracking(*args)
    @previously_changed = self.changes
    @changed_attributes.clear
    return true
  else
    return false
  end
end

#set_attributes_as_current(*attrs) ⇒ Object



116
117
118
119
120
121
# File 'lib/api_resource/attributes.rb', line 116

def set_attributes_as_current(*attrs)
  @changed_attributes.clear and return if attrs.blank?
  attrs.each do |attr|
    @changed_attributes.delete(attr.to_s)
  end
end