Class: Licensed::DependencyRecord::License

Inherits:
Object
  • Object
show all
Defined in:
lib/licensed/dependency_record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ License

Returns a new instance of License.



12
13
14
15
16
17
18
19
20
21
# File 'lib/licensed/dependency_record.rb', line 12

def initialize(content)
  @sources = []

  if content.is_a?(String)
    @text = content.to_s
  elsif content.respond_to?(:[])
    @sources.concat content["sources"].to_s.split(", ")
    @text = content["text"]
  end
end

Instance Attribute Details

#sourcesObject (readonly)

Returns the value of attribute sources.



11
12
13
# File 'lib/licensed/dependency_record.rb', line 11

def sources
  @sources
end

#textObject (readonly)

Returns the value of attribute text.



11
12
13
# File 'lib/licensed/dependency_record.rb', line 11

def text
  @text
end

Instance Method Details

#keyObject



31
32
33
34
35
36
37
# File 'lib/licensed/dependency_record.rb', line 31

def key
  @key ||= begin
    # rubocop:disable GitHub/InsecureHashAlgorithm
    sources.join("") + ":" + Digest::XXHash64.digest(text).to_s
    # rubocop:enable GitHub/InsecureHashAlgorithm
  end
end

#to_cacheObject



23
24
25
26
27
28
29
# File 'lib/licensed/dependency_record.rb', line 23

def to_cache
  return text if sources.empty?
  {
    "sources" => sources.join(", "),
    "text" => text
  }
end