Sha256: 90ae0f8b8a0255176b18506fac74aff54d3000d5d85fc12faca1b2d81fb67961

Contents?: true

Size: 548 Bytes

Versions: 15

Compression:

Stored size: 548 Bytes

Contents

# frozen_string_literal: true

class Gutentag::Dirty
  def self.call(instance, tag_names)
    new(instance, tag_names).call
  end

  def initialize(instance, tag_names)
    @instance  = instance
    @tag_names = tag_names
  end

  def call
    return unless changes.present?

    instance.tag_names_will_change!
    instance.changed_attributes[:tag_names] = existing
  end

  private

  attr_reader :instance, :tag_names

  def changes
    (existing + tag_names).uniq - (existing & tag_names)
  end

  def existing
    instance.tag_names
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
gutentag-2.6.2 lib/gutentag/dirty.rb
gutentag-2.6.1 lib/gutentag/dirty.rb
gutentag-2.6.0 lib/gutentag/dirty.rb
gutentag-2.5.4 lib/gutentag/dirty.rb
gutentag-2.5.3 lib/gutentag/dirty.rb
gutentag-2.5.2 lib/gutentag/dirty.rb
gutentag-2.5.1 lib/gutentag/dirty.rb
gutentag-2.5.0 lib/gutentag/dirty.rb
gutentag-2.4.1 lib/gutentag/dirty.rb
gutentag-2.4.0 lib/gutentag/dirty.rb
gutentag-2.3.2 lib/gutentag/dirty.rb
gutentag-2.3.1 lib/gutentag/dirty.rb
gutentag-2.3.0 lib/gutentag/dirty.rb
gutentag-2.2.1 lib/gutentag/dirty.rb
gutentag-2.2.0 lib/gutentag/dirty.rb