module ConsoleUpdate::SingletonMethods

Public Instance Methods

console_update(records, options={}) click to toggle source

This is the main method for updating records. All other update-like methods pass their options through here.

Options:

:only

Only edit these attributes.

:except

Edit default attributes except for these.

Examples:

records = Url.all :limit=>10
Url.console_update records
Url.console_update records, :only=>%w{column1}
Url.console_update records, :except=>%w{column1}
# File lib/console_update.rb, line 59
def console_update(records, options={})
  begin
    editable_attributes_array = records.map {|e| e.console_editable_attributes(options) }
    editable_string = filter.hashes_to_string(editable_attributes_array)
    new_attributes_array = editor_update(editable_string)
    records.each do |record|
      if (record_attributes = new_attributes_array.detect {|e| e['id'] == record.id })
        record.update_console_attributes(record_attributes)
      end
    end
  rescue ConsoleUpdate::Filter::AbstractMethodError
    puts "Undefined filter method for #{ConsoleUpdate::filter} filter"
  rescue StandardError=>e
    puts "Some record(s) didn't update because of this error: #{e}"
  ensure
    #this attribute should only last duration of method
    reset_editable_attribute_names
  end
end
find_and_console_update(id, options={}) click to toggle source

Console updates a record given an id.

# File lib/console_update.rb, line 84
def find_and_console_update(id, options={})
  console_update([find(id)], options)
end