Class: Spandx::Python::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/spandx/python/source.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Source

Returns a new instance of Source.



8
9
10
11
12
# File 'lib/spandx/python/source.rb', line 8

def initialize(source)
  @name = source['name']
  @uri = URI.parse(source['url'])
  @verify_ssl = source['verify_ssl']
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/spandx/python/source.rb', line 6

def name
  @name
end

#uriObject (readonly)

Returns the value of attribute uri.



6
7
8
# File 'lib/spandx/python/source.rb', line 6

def uri
  @uri
end

#verify_sslObject (readonly)

Returns the value of attribute verify_ssl.



6
7
8
# File 'lib/spandx/python/source.rb', line 6

def verify_ssl
  @verify_ssl
end

Class Method Details

.defaultObject



51
52
53
54
55
56
57
# File 'lib/spandx/python/source.rb', line 51

def default
  new(
    'name' => 'pypi',
    'url' => 'https://pypi.org/simple',
    'verify_ssl' => true
  )
end

.sources_from(json) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/spandx/python/source.rb', line 42

def sources_from(json)
  meta = json['_meta']
  meta['sources'].map do |hash|
    new(hash)
  rescue URI::InvalidURIError
    default
  end
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
35
# File 'lib/spandx/python/source.rb', line 31

def ==(other)
  name == other.name &&
    uri.to_s == other.uri.to_s &&
    verify_ssl == other.verify_ssl
end

#eql(other) ⇒ Object



37
38
39
# File 'lib/spandx/python/source.rb', line 37

def eql(other)
  self == other
end

#hostObject



14
15
16
# File 'lib/spandx/python/source.rb', line 14

def host
  @uri.host
end

#lookup(name, version, http: Spandx.http) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/spandx/python/source.rb', line 22

def lookup(name, version, http: Spandx.http)
  response = http.get(uri_for(name, version))
  if http.ok?(response)
    Oj.load(response.body)
  else
    {}
  end
end

#uri_for(name, version) ⇒ Object



18
19
20
# File 'lib/spandx/python/source.rb', line 18

def uri_for(name, version)
  "https://#{host}/pypi/#{name}/#{version}/json"
end