module ConsoleUpdate::ClassMethods
Public Instance Methods
can_console_update(options={})
click to toggle source
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.
# 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
Private Instance Methods
default_types_to_exclude()
click to toggle source
# File lib/console_update.rb, line 39 def default_types_to_exclude [:datetime, :timestamp, :binary, :time, :timestamp] end
get_default_editable_attributes()
click to toggle source
# File lib/console_update.rb, line 43 def get_default_editable_attributes self.columns.select {|e| !default_types_to_exclude.include?(e.type) }.map(&:name) end