Module: ConsoleUpdate::ClassMethods

Defined in:
lib/console_update.rb

Instance Method Summary collapse

Instance Method Details

#can_console_update(options = {}) ⇒ Object

Enable a model to be updated via the console and an editor. By default editable attributes are columns with text, boolean or integer-like values.

Options:

:only

Sets these attributes as the default editable attributes.

:except

Sets the default editable attributes as normal except for these attributes.

:editor

Overrides global editor for just this model.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/console_update.rb', line 21

def can_console_update(options={})
  cattr_accessor :console_editor
  self.console_editor = options[:editor] || ConsoleUpdate.editor
  
  cattr_accessor :default_editable_attributes
  if options[:only]
    self.default_editable_attributes = options[:only]
  elsif options[:except]
    self.default_editable_attributes = self.column_names.select {|e| !options[:except].include?(e) }
  else
    self.default_editable_attributes = get_default_editable_attributes 
  end
  
  extend SingletonMethods
  send :include, InstanceMethods
end