Module: Berkshelf::Location
- Included in:
- ChefAPILocation, GitLocation, PathLocation, SiteLocation
- Defined in:
- lib/berkshelf/location.rb
Overview
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- OPSCODE_COMMUNITY_API =
'http://cookbooks.opscode.com/api/v1/cookbooks'.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version_constraint ⇒ Object
readonly
Returns the value of attribute version_constraint.
Class Method Summary collapse
- .included(base) ⇒ Object
-
.init(name, constraint, options = {}) ⇒ SiteLocation, ...
Creates a new instance of a Class implementing Location with the given name and constraint.
Instance Method Summary collapse
- #download(destination) ⇒ Berkshelf::CachedCookbook
- #downloaded? ⇒ Boolean
- #initialize(name, version_constraint, options = {}) ⇒ Object
- #to_hash ⇒ Object
- #to_json ⇒ Object
-
#validate_cached(cached_cookbook) ⇒ Boolean
Ensure the retrieved CachedCookbook is valid.
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
117 118 119 |
# File 'lib/berkshelf/location.rb', line 117 def name @name end |
#version_constraint ⇒ Object (readonly)
Returns the value of attribute version_constraint.
118 119 120 |
# File 'lib/berkshelf/location.rb', line 118 def version_constraint @version_constraint end |
Class Method Details
.included(base) ⇒ Object
61 62 63 |
# File 'lib/berkshelf/location.rb', line 61 def included(base) base.send :extend, ClassMethods end |
.init(name, constraint, options = {}) ⇒ SiteLocation, ...
Creates a new instance of a Class implementing Location with the given name and constraint. Which Class to instantiated is determined by the values in the given options Hash. Source Locations have an associated location_key registered with CookbookSource. If your options Hash contains a key matching one of these location_keys then the Class who registered that location_key will be instantiated. If you do not provide an option with a matching location_key a SiteLocation class will be instantiated.
94 95 96 97 98 |
# File 'lib/berkshelf/location.rb', line 94 def init(name, constraint, = {}) klass = () klass.new(name, constraint, ) end |
Instance Method Details
#download(destination) ⇒ Berkshelf::CachedCookbook
132 133 134 |
# File 'lib/berkshelf/location.rb', line 132 def download(destination) raise AbstractFunction end |
#downloaded? ⇒ Boolean
137 138 139 |
# File 'lib/berkshelf/location.rb', line 137 def downloaded? @downloaded_status end |
#initialize(name, version_constraint, options = {}) ⇒ Object
123 124 125 126 127 |
# File 'lib/berkshelf/location.rb', line 123 def initialize(name, version_constraint, = {}) @name = name @version_constraint = version_constraint @downloaded_status = false end |
#to_hash ⇒ Object
164 165 166 167 168 |
# File 'lib/berkshelf/location.rb', line 164 def to_hash { type: self.class.location_key } end |
#to_json ⇒ Object
170 171 172 |
# File 'lib/berkshelf/location.rb', line 170 def to_json MultiJson.dump(self.to_hash, pretty: true) end |
#validate_cached(cached_cookbook) ⇒ Boolean
Ensure the retrieved CachedCookbook is valid
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/berkshelf/location.rb', line 151 def validate_cached(cached_cookbook) unless version_constraint.satisfies?(cached_cookbook.version) raise ConstraintNotSatisfied, "A cookbook satisfying '#{self.name}' (#{self.version_constraint}) not found at #{self}" end # JW TODO: Safe to uncomment when when Opscode makes the 'name' a required attribute in Cookbook metadata # unless self.name == cached_cookbook.cookbook_name # raise AmbiguousCookbookName, "Expected a cookbook at #{self} to be named '#{self.name}'. Did you set the 'name' attribute in your Cookbooks metadata? If you didn't, the name of the directory will be used as the name of your Cookbook (awful, right?)." # end true end |