Class: PriceLogEntry

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/generators/price_log/templates/price_log_entry.rb

Instance Method Summary collapse

Instance Method Details

#pretty_printObject



35
36
37
# File 'lib/generators/price_log/templates/price_log_entry.rb', line 35

def pretty_print
  puts "#{self.priceable_type}, #{self.priceable_id}, #{self.priceable_field_name}, start_date: #{self.start_date}, end_date: #{self.end_date}"
end

#resolve_datesObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/price_log/templates/price_log_entry.rb', line 21

def resolve_dates
  _all_ = PriceLogEntry.all_for_priceable(self.priceable_type, self.priceable_id, self.priceable_field_name)
  prev_start_date = nil
  self.logger.info "Recalculates #{self.priceable_type}, #{self.priceable_id}, #{self.priceable_field_name}"
  _all_.order("start_date DESC").each do |ple|
    unless prev_start_date.nil?
      ple.end_date = prev_start_date
      ple.save!
    end
    prev_start_date = ple.start_date
  end
  true
end