Class: Gemsurance::GemInfoRetriever::GemInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/gemsurance/gem_info_retriever.rb

Constant Summary collapse

GEM_ATTRIBUTES =
[:name, :current_version, :newest_version, :in_gem_file, :homepage_uri, :source_code_uri, :documentation_uri, :status, :vulnerabilities]
STATUS_OUTDATED =
'outdated'
STATUS_CURRENT =
'current'
STATUS_VULNERABLE =
'vulnerable'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, current_version, newest_version, in_gem_file, homepage_uri, source_code_uri, documentation_uri, status = STATUS_CURRENT) ⇒ GemInfo

Returns a new instance of GemInfo.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gemsurance/gem_info_retriever.rb', line 14

def initialize(name, current_version, newest_version, in_gem_file, homepage_uri, source_code_uri, documentation_uri, status = STATUS_CURRENT)
  @name = name
  @current_version = current_version
  @newest_version = newest_version
  @in_gem_file = in_gem_file
  @homepage_uri = homepage_uri
  @documentation_uri = documentation_uri
  @source_code_uri = source_code_uri
  @status = status
  @vulnerabilities = []
end

Instance Attribute Details

#current_versionObject (readonly)

Returns the value of attribute current_version.



11
12
13
# File 'lib/gemsurance/gem_info_retriever.rb', line 11

def current_version
  @current_version
end

#documentation_uriObject (readonly)

Returns the value of attribute documentation_uri.



11
12
13
# File 'lib/gemsurance/gem_info_retriever.rb', line 11

def documentation_uri
  @documentation_uri
end

#homepage_uriObject (readonly)

Returns the value of attribute homepage_uri.



11
12
13
# File 'lib/gemsurance/gem_info_retriever.rb', line 11

def homepage_uri
  @homepage_uri
end

#in_gem_fileObject (readonly)

Returns the value of attribute in_gem_file.



11
12
13
# File 'lib/gemsurance/gem_info_retriever.rb', line 11

def in_gem_file
  @in_gem_file
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/gemsurance/gem_info_retriever.rb', line 11

def name
  @name
end

#newest_versionObject (readonly)

Returns the value of attribute newest_version.



11
12
13
# File 'lib/gemsurance/gem_info_retriever.rb', line 11

def newest_version
  @newest_version
end

#source_code_uriObject (readonly)

Returns the value of attribute source_code_uri.



11
12
13
# File 'lib/gemsurance/gem_info_retriever.rb', line 11

def source_code_uri
  @source_code_uri
end

#statusObject (readonly)

Returns the value of attribute status.



11
12
13
# File 'lib/gemsurance/gem_info_retriever.rb', line 11

def status
  @status
end

#vulnerabilitiesObject (readonly)

Returns the value of attribute vulnerabilities.



11
12
13
# File 'lib/gemsurance/gem_info_retriever.rb', line 11

def vulnerabilities
  @vulnerabilities
end

Instance Method Details

#==(other) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/gemsurance/gem_info_retriever.rb', line 43

def ==(other)
  @name == other.name &&
    @current_version == other.current_version &&
    @newest_version == other.newest_version &&
    @status == other.instance_variable_get(:@status) &&
    @vulnerabilities == other.vulnerabilities
end

#add_vulnerability!(vulnerability) ⇒ Object



26
27
28
29
# File 'lib/gemsurance/gem_info_retriever.rb', line 26

def add_vulnerability!(vulnerability)
  @status = STATUS_VULNERABLE
  @vulnerabilities << vulnerability
end

#current?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/gemsurance/gem_info_retriever.rb', line 35

def current?
  @status == STATUS_CURRENT
end

#outdated?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/gemsurance/gem_info_retriever.rb', line 31

def outdated?
  @status == STATUS_OUTDATED
end

#to_csvObject



51
52
53
# File 'lib/gemsurance/gem_info_retriever.rb', line 51

def to_csv
  formatted_values.to_csv
end

#to_hashObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gemsurance/gem_info_retriever.rb', line 55

def to_hash
  {
    'in_gem_file' =>  in_gem_file,
    'bundle_version' =>  current_version.to_s,
    'newest_version' =>  newest_version.to_s,
    'status' => human_status,
    'homepage_url' =>  homepage_uri,
    'source_code_url' =>  source_code_uri,
    'documentation_url' =>  documentation_uri,
    'vulnerabilities' => vulns_to_hash
  }
end

#vulnerable?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/gemsurance/gem_info_retriever.rb', line 39

def vulnerable?
  @status == STATUS_VULNERABLE
end