Class: Workarea::Release::Changes

Inherits:
Object
  • Object
show all
Defined in:
app/models/workarea/release/changes.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(releasable) ⇒ Changes

Returns a new instance of Changes.



11
12
13
# File 'app/models/workarea/release/changes.rb', line 11

def initialize(releasable)
  @releasable = releasable
end

Instance Attribute Details

#releasableObject (readonly)

Returns the value of attribute releasable.



4
5
6
# File 'app/models/workarea/release/changes.rb', line 4

def releasable
  @releasable
end

Class Method Details

.tracked_change?(key, old_value, new_value) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
# File 'app/models/workarea/release/changes.rb', line 6

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

Instance Method Details

#change_appears_in_earlier_release?(key, new_value) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
# File 'app/models/workarea/release/changes.rb', line 38

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

#to_hObject



15
16
17
18
19
20
21
22
# File 'app/models/workarea/release/changes.rb', line 15

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

#to_originals_hObject



24
25
26
27
28
29
30
31
# File 'app/models/workarea/release/changes.rb', line 24

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

#track_change?(key, old_value, new_value) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'app/models/workarea/release/changes.rb', line 33

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