Module: CsvRecord::Writer::InstanceMethods
- Defined in:
- lib/csv_record/csv_writers/instance_writer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #__destroy__ ⇒ Object (also: #destroy)
- #__save__(validate = true) ⇒ Object (also: #save)
- #__update_attribute__(field, value) ⇒ Object (also: #update_attribute)
- #__update_attributes__(params = {validate: true}) {|_self| ... } ⇒ Object (also: #update_attributes)
- #new_record? ⇒ Boolean
Class Method Details
.included(receiver) ⇒ Object
3 4 5 |
# File 'lib/csv_record/csv_writers/instance_writer.rb', line 3 def self.included(receiver) receiver.send :attr_accessor, :id end |
Instance Method Details
#__destroy__ ⇒ Object Also known as: destroy
37 38 39 40 41 42 43 44 45 |
# File 'lib/csv_record/csv_writers/instance_writer.rb', line 37 def __destroy__ self.class.parse_database_file do |row| new_row = row new_row = nil if self.id.to_i == row.field('id').to_i new_row end empty_fields true end |
#__save__(validate = true) ⇒ Object Also known as: save
7 8 9 10 11 12 13 |
# File 'lib/csv_record/csv_writers/instance_writer.rb', line 7 def __save__(validate=true) if (not validate) || self.valid? self.new_record? ? self.append_registry : self.update_registry else false end end |
#__update_attribute__(field, value) ⇒ Object Also known as: update_attribute
19 20 21 22 |
# File 'lib/csv_record/csv_writers/instance_writer.rb', line 19 def __update_attribute__(field, value) self.public_send "#{field}=", value self.save false end |
#__update_attributes__(params = {validate: true}) {|_self| ... } ⇒ Object Also known as: update_attributes
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/csv_record/csv_writers/instance_writer.rb', line 24 def __update_attributes__(params={validate: true}) validate = params[:validate] params.delete :validate params.each do |field, value| self.public_send "#{field}=", value end yield self if block_given? self.save validate end |
#new_record? ⇒ Boolean
15 16 17 |
# File 'lib/csv_record/csv_writers/instance_writer.rb', line 15 def new_record? self.created_at.nil? || self.id.nil? end |