Class: Spandx::Python::Source
- Inherits:
-
Object
- Object
- Spandx::Python::Source
- Defined in:
- lib/spandx/python/source.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#verify_ssl ⇒ Object
readonly
Returns the value of attribute verify_ssl.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql(other) ⇒ Object
- #host ⇒ Object
-
#initialize(source) ⇒ Source
constructor
A new instance of Source.
- #lookup(name, version, http: Spandx.http) ⇒ Object
- #uri_for(name, version) ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/spandx/python/source.rb', line 6 def name @name end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
6 7 8 |
# File 'lib/spandx/python/source.rb', line 6 def uri @uri end |
#verify_ssl ⇒ Object (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
.default ⇒ Object
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) = json['_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 |
#host ⇒ Object
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 |