Module: OldApiResource::Attributes::InstanceMethods

Defined in:
lib/old_api_resource/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute?(name) ⇒ Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/old_api_resource/attributes.rb', line 140

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

#attributes=(new_attrs) ⇒ Object

set new attributes



107
108
109
110
111
112
# File 'lib/old_api_resource/attributes.rb', line 107

def attributes=(new_attrs)
  new_attrs.each_pair do |k,v|
    self.send("#{k}=",v)
  end
  new_attrs
end

#protected_attribute?(name) ⇒ Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/old_api_resource/attributes.rb', line 144

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

#reset_attribute_changes(*attrs) ⇒ Object



131
132
133
134
135
136
137
138
# File 'lib/old_api_resource/attributes.rb', line 131

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)


148
149
150
151
152
153
154
155
156
157
# File 'lib/old_api_resource/attributes.rb', line 148

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



114
115
116
117
118
119
120
121
122
# File 'lib/old_api_resource/attributes.rb', line 114

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



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

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