Sha256: e1767b324e80a21336054bfbc8560e762f8bffd7bb260af538848f5db3ac221c

Contents?: true

Size: 1.19 KB

Versions: 23

Compression:

Stored size: 1.19 KB

Contents

module Piggybak
  module FormattedChanges
    extend ActiveSupport::Concern

    module InstanceMethods
      def new_destroy_changes(type)
        text = "#{self.class.to_s.gsub(/Piggybak::/, '')} ##{self.id} #{type}:<br />"
        self.attributes.each do |k, v|
          if !["upated_at", "created_at", "id", "order_id", "billing_address_id", "shipping_address_id"].include?(k)
            if v.is_a?(BigDecimal)
              text += "#{k}: $#{format("%.2f", v)}<br />"
            else
              text += "#{k}: #{v}<br />"
            end
          end
        end

        return text
      end

      def formatted_changes
        text = "#{self.class.to_s.gsub(/Piggybak::/, '')} ##{self.id} changes:<br />"
        self.changes.each do |k, v|
          if !["updated_at", "id", "billing_address_id", "shipping_address_id", "created_at"].include?(k)
            if v[0].is_a?(BigDecimal)
              text += "#{k}: $#{format("%.2f", v[0])} to $#{format("%.2f", v[1])}<br />"
            else
              text += "#{k}: #{v[0]} to #{v[1]}<br />"
            end
          end
        end

        return text
      end
    end
  end
end

::ActiveRecord::Base.send :include, Piggybak::FormattedChanges

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
piggybak-0.5.1 lib/formatted_changes.rb
piggybak-0.5.0 lib/formatted_changes.rb
piggybak-0.4.39 lib/formatted_changes.rb
piggybak-0.4.38 lib/formatted_changes.rb
piggybak-0.4.37 lib/formatted_changes.rb
piggybak-0.4.36 lib/formatted_changes.rb
piggybak-0.4.35 lib/formatted_changes.rb
piggybak-0.4.34 lib/formatted_changes.rb
piggybak-0.4.33 lib/formatted_changes.rb
piggybak-0.4.32 lib/formatted_changes.rb
piggybak-0.4.31 lib/formatted_changes.rb
piggybak-0.4.30 lib/formatted_changes.rb
piggybak-0.4.29 lib/formatted_changes.rb
piggybak-0.4.28 lib/formatted_changes.rb
piggybak-0.4.27 lib/formatted_changes.rb
piggybak-0.4.26 lib/formatted_changes.rb
piggybak-0.4.25 lib/formatted_changes.rb
piggybak-0.4.24 lib/formatted_changes.rb
piggybak-0.4.23 lib/formatted_changes.rb
piggybak-0.4.22 lib/formatted_changes.rb