Sha256: 3a758228142cf50dd8ee23af6d640b586fc157ca930e80a179d56e1f19961f4c

Contents?: true

Size: 644 Bytes

Versions: 15

Compression:

Stored size: 644 Bytes

Contents

module OverrideSongAttributesTheRails4Way
  def attributes
    if name
      super.merge(name: name)
    else
      super
    end
  end

  def changed_attributes
    if name
      super.merge(name: name)
    else
      super
    end
  end
end

class Song < ActiveRecord::Base
  has_paper_trail

  # Uses an integer of seconds to hold the length of the song
  def length=(minutes)
    write_attribute(:length, minutes.to_i * 60)
  end

  def length
    read_attribute(:length) / 60
  end

  if ActiveRecord::VERSION::MAJOR >= 5
    attribute :name, :string
  else
    attr_accessor :name
    prepend OverrideSongAttributesTheRails4Way
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
paper_trail_scrapbook-0.1.9 spec/dummy_app/app/models/song.rb
paper_trail_scrapbook-0.1.8 spec/dummy_app/app/models/song.rb
paper_trail_scrapbook-0.1.7 spec/dummy_app/app/models/song.rb
paper_trail_scrapbook-0.1.6 spec/dummy_app/app/models/song.rb
paper_trail-7.1.0 spec/dummy_app/app/models/song.rb
paper_trail_scrapbook-0.1.3 spec/dummy_app/app/models/song.rb
paper_trail_scrapbook-0.1.2 spec/dummy_app/app/models/song.rb
paper_trail_scrapbook-0.1.1 spec/dummy_app/app/models/song.rb
paper_trail_scrapbook-0.1.0 spec/dummy_app/app/models/song.rb
paper_trail_scrapbook-0.0.2 spec/dummy_app/app/models/song.rb
paper_trail-7.0.3 test/dummy/app/models/song.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/paper_trail-7.0.2/test/dummy/app/models/song.rb
paper_trail-7.0.2 test/dummy/app/models/song.rb
paper_trail-7.0.1 test/dummy/app/models/song.rb
paper_trail-7.0.0 test/dummy/app/models/song.rb