Module: ConsoleUpdate::InstanceMethods

Defined in:
lib/console_update.rb

Instance Method Summary collapse

Instance Method Details

#console_editable_attributes(options) ⇒ Object



142
143
144
145
146
# File 'lib/console_update.rb', line 142

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.



119
120
121
# File 'lib/console_update.rb', line 119

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

#get_console_attributes(attribute_names) ⇒ Object



135
136
137
138
139
140
# File 'lib/console_update.rb', line 135

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:



124
125
126
127
128
129
130
131
132
133
# File 'lib/console_update.rb', line 124

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