Class: Berkshelf::Source
- Inherits:
-
Object
- Object
- Berkshelf::Source
- Includes:
- Comparable
- Defined in:
- lib/berkshelf/source.rb
Instance Attribute Summary collapse
- #uri ⇒ Berkshelf::SourceURI readonly
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#build_universe ⇒ Array<APIClient::RemoteCookbook>
Forcefully obtain the universe from the API endpoint and assign it to #universe.
- #cookbook(name, version) ⇒ APIClient::RemoteCookbook
-
#default? ⇒ true, false
Determine if this source is a “default” source, as defined in the Berksfile.
-
#initialize(uri) ⇒ Source
constructor
A new instance of Source.
- #latest(name) ⇒ APIClient::RemoteCookbook
-
#search(name) ⇒ Array<APIClient::RemoteCookbook]
The list of remote cookbooks that match the given query.
- #to_s ⇒ Object
-
#universe ⇒ Array<APIClient::RemoteCookbook>
Return the universe from the API endpoint.
- #versions(name) ⇒ Array<APIClient::RemoteCookbook>
Constructor Details
Instance Attribute Details
#uri ⇒ Berkshelf::SourceURI (readonly)
8 9 10 |
# File 'lib/berkshelf/source.rb', line 8 def uri @uri end |
Instance Method Details
#==(other) ⇒ Object
86 87 88 89 |
# File 'lib/berkshelf/source.rb', line 86 def ==(other) return false unless other.is_a?(self.class) uri == other.uri end |
#build_universe ⇒ Array<APIClient::RemoteCookbook>
21 22 23 24 25 26 |
# File 'lib/berkshelf/source.rb', line 21 def build_universe @universe = api_client.universe rescue => ex @universe = Array.new raise ex end |
#cookbook(name, version) ⇒ APIClient::RemoteCookbook
43 44 45 |
# File 'lib/berkshelf/source.rb', line 43 def cookbook(name, version) universe.find { |cookbook| cookbook.name == name && cookbook.version == version } end |
#default? ⇒ true, false
Determine if this source is a “default” source, as defined in the Berksfile.
64 65 66 |
# File 'lib/berkshelf/source.rb', line 64 def default? @default_ ||= @uri.host == URI.parse(Berksfile::DEFAULT_API_URL).host end |
#latest(name) ⇒ APIClient::RemoteCookbook
71 72 73 |
# File 'lib/berkshelf/source.rb', line 71 def latest(name) versions(name).sort.last end |
#search(name) ⇒ Array<APIClient::RemoteCookbook]
The list of remote cookbooks that match the given query.
52 53 54 55 56 57 |
# File 'lib/berkshelf/source.rb', line 52 def search(name) universe .select { |cookbook| cookbook.name =~ Regexp.new(name) } .group_by(&:name) .collect { |name, versions| versions.max_by(&:version) } end |
#to_s ⇒ Object
82 83 84 |
# File 'lib/berkshelf/source.rb', line 82 def to_s "#{uri}" end |
#universe ⇒ Array<APIClient::RemoteCookbook>
Return the universe from the API endpoint.
This is lazily loaded so the universe will be retrieved from the API endpoint on the first call and cached for future calls. Send the #build_universe message if you want to reload the cached universe.
35 36 37 |
# File 'lib/berkshelf/source.rb', line 35 def universe @universe || build_universe end |
#versions(name) ⇒ Array<APIClient::RemoteCookbook>
78 79 80 |
# File 'lib/berkshelf/source.rb', line 78 def versions(name) universe.select { |cookbook| cookbook.name == name } end |