Module ConsoleUpdate::SingletonMethods

  1. lib/console_update.rb

Methods

public instance

  1. console_update
  2. find_and_console_update

Public instance methods

console_update (records, options={})

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}
[show source]
# File lib/console_update.rb, line 60
    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 Test::Unit::AssertionFailedError=>e
        raise e
      rescue Exception=>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={})

Console updates a record given an id.

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