Module: ConsoleUpdate::InstanceMethods

Defined in:
lib/console_update.rb

Instance Method Summary collapse

Instance Method Details

#console_editable_attributes(options) ⇒ Object



139
140
141
142
143
# File 'lib/console_update.rb', line 139

def console_editable_attributes(options)
  fresh_attributes = get_console_attributes(self.class.editable_attribute_names(options))
  fresh_attributes['id'] ||= self.id
  fresh_attributes
end

#console_update(options = {}) ⇒ Object

Console updates the object.



116
117
118
# File 'lib/console_update.rb', line 116

def console_update(options={}) 
  self.class.console_update([self], options)
end

#get_console_attributes(attribute_names) ⇒ Object



132
133
134
135
136
137
# File 'lib/console_update.rb', line 132

def get_console_attributes(attribute_names)
  attribute_names.inject({}) {|h,e|
    h[e] = attributes.has_key?(e) ? attributes[e] : send(e)
    h
  }
end

#update_console_attributes(new_attributes) ⇒ Object

:stopdoc:



121
122
123
124
125
126
127
128
129
130
# File 'lib/console_update.rb', line 121

def update_console_attributes(new_attributes)
  # delete if value is the same or is an attribute that isn't supposed to be edited
  new_attributes.delete_if {|k,v|
    attributes[k] == v || !self.class.editable_attribute_names.include?(k)
  }
  new_attributes.each do |k, v|  
    send("#{k}=", v)  
  end
  save
end