Class: ReactorSDK::Resources::LibraryComparisonEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/reactor_sdk/resources/library_comparison_entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_id:, resource_type:, current_library_id:, baseline_library_id:, current_resource:, baseline_resource:, current_revision_id:, baseline_revision_id:, current_comprehensive_resource:, baseline_comprehensive_resource:) ⇒ LibraryComparisonEntry

Returns a new instance of LibraryComparisonEntry.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 17

def initialize(
  resource_id:,
  resource_type:,
  current_library_id:,
  baseline_library_id:,
  current_resource:,
  baseline_resource:,
  current_revision_id:,
  baseline_revision_id:,
  current_comprehensive_resource:,
  baseline_comprehensive_resource:
)
  @resource_id = resource_id
  @resource_type = resource_type
  @current_library_id = current_library_id
  @baseline_library_id = baseline_library_id
  @current_resource = current_resource
  @baseline_resource = baseline_resource
  @current_revision_id = current_revision_id
  @baseline_revision_id = baseline_revision_id
  @current_comprehensive_resource = current_comprehensive_resource
  @baseline_comprehensive_resource = baseline_comprehensive_resource
end

Instance Attribute Details

#baseline_comprehensive_resourceObject (readonly)

Returns the value of attribute baseline_comprehensive_resource.



6
7
8
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 6

def baseline_comprehensive_resource
  @baseline_comprehensive_resource
end

#baseline_library_idObject (readonly)

Returns the value of attribute baseline_library_id.



6
7
8
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 6

def baseline_library_id
  @baseline_library_id
end

#baseline_resourceObject (readonly)

Returns the value of attribute baseline_resource.



6
7
8
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 6

def baseline_resource
  @baseline_resource
end

#baseline_revision_idObject (readonly)

Returns the value of attribute baseline_revision_id.



6
7
8
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 6

def baseline_revision_id
  @baseline_revision_id
end

#current_comprehensive_resourceObject (readonly)

Returns the value of attribute current_comprehensive_resource.



6
7
8
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 6

def current_comprehensive_resource
  @current_comprehensive_resource
end

#current_library_idObject (readonly)

Returns the value of attribute current_library_id.



6
7
8
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 6

def current_library_id
  @current_library_id
end

#current_resourceObject (readonly)

Returns the value of attribute current_resource.



6
7
8
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 6

def current_resource
  @current_resource
end

#current_revision_idObject (readonly)

Returns the value of attribute current_revision_id.



6
7
8
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 6

def current_revision_id
  @current_revision_id
end

#resource_idObject (readonly)

Returns the value of attribute resource_id.



6
7
8
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 6

def resource_id
  @resource_id
end

#resource_typeObject (readonly)

Returns the value of attribute resource_type.



6
7
8
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 6

def resource_type
  @resource_type
end

Instance Method Details

#added?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 56

def added?
  present_in_current? && !present_in_baseline?
end

#baseline_normalized_jsonObject



98
99
100
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 98

def baseline_normalized_json
  baseline_comprehensive_resource&.normalized_json.to_s
end

#baseline_normalized_payloadObject



90
91
92
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 90

def baseline_normalized_payload
  baseline_comprehensive_resource&.normalized_payload
end

#changed?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 74

def changed?
  !unchanged?
end

#changeset_document(position: nil) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 102

def changeset_document(position: nil)
  document = {
    path: changeset_path,
    language: 'json',
    old_content: baseline_normalized_json,
    new_content: current_normalized_json,
    metadata: 
  }
  document[:position] = position unless position.nil?
  document
end

#current_normalized_jsonObject



94
95
96
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 94

def current_normalized_json
  current_comprehensive_resource&.normalized_json.to_s
end

#current_normalized_payloadObject



86
87
88
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 86

def current_normalized_payload
  current_comprehensive_resource&.normalized_payload
end

#modified?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 64

def modified?
  present_in_current? && present_in_baseline? && !unchanged?
end

#present_in_baseline?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 82

def present_in_baseline?
  !baseline_resource.nil?
end

#present_in_current?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 78

def present_in_current?
  !current_resource.nil?
end

#removed?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 60

def removed?
  !present_in_current? && present_in_baseline?
end

#resource_nameObject



41
42
43
44
45
46
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 41

def resource_name
  return current_resource.name if current_resource.respond_to?(:name)
  return baseline_resource.name if baseline_resource.respond_to?(:name)

  nil
end

#statusObject



48
49
50
51
52
53
54
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 48

def status
  return 'added' if added?
  return 'removed' if removed?
  return 'unchanged' if unchanged?

  'modified'
end

#unchanged?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
# File 'lib/reactor_sdk/resources/library_comparison_entry.rb', line 68

def unchanged?
  return false unless present_in_current? && present_in_baseline?

  same_revision? || same_normalized_payload?
end