Sha256: 4bfc8b5f784012ca91138c253033566236aa2d4f69d247b82f58d797775c9ece

Contents?: true

Size: 1.29 KB

Versions: 28

Compression:

Stored size: 1.29 KB

Contents

module Workarea
  class Release
    class Changes
      attr_reader :releasable

      def self.tracked_change?(key, old_value, new_value)
        !key.in?(Workarea.config.untracked_release_changes_fields) &&
          (old_value.present? || new_value.present?)
      end

      def initialize(releasable)
        @releasable = releasable
      end

      def to_h
        releasable.changes.keys.inject({}) do |memo, key|
          old_value, new_value = *releasable.changes[key]

          memo[key] = new_value if track_change?(key, old_value, new_value)
          memo
        end
      end

      def to_originals_h
        releasable.changes.keys.inject({}) do |memo, key|
          old_value, new_value = *releasable.changes[key]

          memo[key] = old_value if track_change?(key, old_value, new_value)
          memo
        end
      end

      def track_change?(key, old_value, new_value)
        self.class.tracked_change?(key, old_value, new_value) &&
          !change_appears_in_earlier_release?(key, new_value)
      end

      def change_appears_in_earlier_release?(key, new_value)
        Release.current.scheduled_before.flat_map(&:changesets).any? do |changeset|
          changeset.releasable == releasable && changeset.includes_change?(key, new_value)
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/models/workarea/release/changes.rb
workarea-core-3.5.26 app/models/workarea/release/changes.rb
workarea-core-3.5.25 app/models/workarea/release/changes.rb
workarea-core-3.5.23 app/models/workarea/release/changes.rb
workarea-core-3.5.22 app/models/workarea/release/changes.rb
workarea-core-3.5.21 app/models/workarea/release/changes.rb
workarea-core-3.5.20 app/models/workarea/release/changes.rb
workarea-core-3.5.19 app/models/workarea/release/changes.rb
workarea-core-3.5.18 app/models/workarea/release/changes.rb
workarea-core-3.5.17 app/models/workarea/release/changes.rb
workarea-core-3.5.16 app/models/workarea/release/changes.rb
workarea-core-3.5.15 app/models/workarea/release/changes.rb
workarea-core-3.5.14 app/models/workarea/release/changes.rb
workarea-core-3.5.13 app/models/workarea/release/changes.rb
workarea-core-3.5.12 app/models/workarea/release/changes.rb
workarea-core-3.5.11 app/models/workarea/release/changes.rb
workarea-core-3.5.10 app/models/workarea/release/changes.rb
workarea-core-3.5.9 app/models/workarea/release/changes.rb
workarea-core-3.5.8 app/models/workarea/release/changes.rb
workarea-core-3.5.7 app/models/workarea/release/changes.rb