Class: Berkshelf::SiteLocation
- Inherits:
-
Object
- Object
- Berkshelf::SiteLocation
- Extended by:
- Forwardable
- Includes:
- Location
- Defined in:
- lib/berkshelf/locations/site_location.rb
Constant Summary collapse
- SHORTNAMES =
{opscode: CommunityREST::V1_API}.freeze
Constants included from Location
Location::OPSCODE_COMMUNITY_API
Instance Attribute Summary collapse
-
#version_constraint ⇒ Object
Returns the value of attribute version_constraint.
Attributes included from Location
Instance Method Summary collapse
- #download(destination) ⇒ Berkshelf::CachedCookbook
-
#initialize(name, version_constraint, options = {}) ⇒ SiteLocation
constructor
A new instance of SiteLocation.
-
#latest_version ⇒ String
Return the latest version that the site location has for the the cookbook.
-
#target_version ⇒ String
Returns a string representing the version of the cookbook that should be downloaded for this location.
- #to_hash ⇒ Object
- #to_s ⇒ Object
Methods included from Location
included, init, #to_json, #validate_cached
Constructor Details
#initialize(name, version_constraint, options = {}) ⇒ SiteLocation
Returns a new instance of SiteLocation.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/berkshelf/locations/site_location.rb', line 20 def initialize(name, version_constraint, = {}) @name = name @version_constraint = version_constraint api_uri = if [:site].nil? SHORTNAMES[:opscode] elsif SHORTNAMES.has_key?([:site]) SHORTNAMES[[:site]] elsif [:site].kind_of?(Symbol) raise InvalidSiteShortnameError.new([:site]) else [:site] end @conn = Berkshelf::CommunityREST.new(api_uri) end |
Instance Attribute Details
#version_constraint ⇒ Object
Returns the value of attribute version_constraint.
9 10 11 |
# File 'lib/berkshelf/locations/site_location.rb', line 9 def version_constraint @version_constraint end |
Instance Method Details
#download(destination) ⇒ Berkshelf::CachedCookbook
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/berkshelf/locations/site_location.rb', line 40 def download(destination) version = target_version berks_path = File.join(destination, "#{name}-#{version}") temp_path = conn.download(name, version) FileUtils.mv(File.join(temp_path, name), berks_path) cached = CachedCookbook.from_store_path(berks_path) validate_cached(cached) cached end |
#latest_version ⇒ String
Return the latest version that the site location has for the the cookbook
56 57 58 |
# File 'lib/berkshelf/locations/site_location.rb', line 56 def latest_version conn.latest_version(name) end |
#target_version ⇒ String
Returns a string representing the version of the cookbook that should be downloaded for this location
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/berkshelf/locations/site_location.rb', line 64 def target_version version = if version_constraint conn.satisfy(name, version_constraint) else latest_version end if version.nil? msg = "Cookbook '#{name}' found at #{self}" msg << " that would satisfy constraint (#{version_constraint}" if version_constraint raise CookbookNotFound, msg end version end |
#to_hash ⇒ Object
80 81 82 |
# File 'lib/berkshelf/locations/site_location.rb', line 80 def to_hash super.merge(value: self.api_uri) end |
#to_s ⇒ Object
84 85 86 |
# File 'lib/berkshelf/locations/site_location.rb', line 84 def to_s "#{self.class.location_key}: '#{api_uri}'" end |