Class: InchCI::Diff::CompareCodeObjects

Inherits:
Object
  • Object
show all
Defined in:
lib/inch_ci/diff.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object1, object2) ⇒ CompareCodeObjects

Returns a new instance of CompareCodeObjects.


26
27
28
29
30
31
# File 'lib/inch_ci/diff.rb', line 26

def initialize(object1, object2)
  @before, @after = object1, object2
  if @before.object_id == @after.object_id
    raise "@before and @after are identical ruby objects. this is bad."
  end
end

Instance Attribute Details

#afterObject (readonly)

Returns the value of attribute after


24
25
26
# File 'lib/inch_ci/diff.rb', line 24

def after
  @after
end

#beforeObject (readonly)

Returns the value of attribute before


24
25
26
# File 'lib/inch_ci/diff.rb', line 24

def before
  @before
end

Instance Method Details

#added?Boolean

Returns:

  • (Boolean)

44
45
46
# File 'lib/inch_ci/diff.rb', line 44

def added?
  @before.nil? && !@after.nil?
end

#changeObject


33
34
35
36
37
38
# File 'lib/inch_ci/diff.rb', line 33

def change
  return 'added' if added?
  return 'improved' if improved?
  return 'degraded' if degraded?
  return 'removed' if removed?
end

#changed?Boolean

Returns:

  • (Boolean)

40
41
42
# File 'lib/inch_ci/diff.rb', line 40

def changed?
  present? && !unchanged?
end

#degraded?Boolean

Returns:

  • (Boolean)

48
49
50
# File 'lib/inch_ci/diff.rb', line 48

def degraded?
  changed? && @before.score > @after.score
end

#improved?Boolean

Returns:

  • (Boolean)

52
53
54
# File 'lib/inch_ci/diff.rb', line 52

def improved?
  changed? && @before.score < @after.score
end

#present?Boolean

Returns:

  • (Boolean)

56
57
58
# File 'lib/inch_ci/diff.rb', line 56

def present?
  @before && @after
end

#removed?Boolean

Returns:

  • (Boolean)

60
61
62
# File 'lib/inch_ci/diff.rb', line 60

def removed?
  !@before.nil? && @after.nil?
end

#unchanged?Boolean

Returns:

  • (Boolean)

64
65
66
# File 'lib/inch_ci/diff.rb', line 64

def unchanged?
  present? && @before.score == @after.score
end