Module: Berkshelf::Location
- Included in:
- ChefAPILocation, GitLocation, PathLocation, SiteLocation
- Defined in:
- lib/berkshelf/location.rb
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
- #initialize(name, version_constraint, options = {}) ⇒ Object
- #to_hash ⇒ Object
- #to_json(options = {}) ⇒ Object
-
#validate_cached(cached_cookbook) ⇒ Boolean
Ensure the retrieved CachedCookbook is valid.
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
118 119 120 |
# File 'lib/berkshelf/location.rb', line 118 def name @name end |
#version_constraint ⇒ Object (readonly)
Returns the value of attribute version_constraint.
119 120 121 |
# File 'lib/berkshelf/location.rb', line 119 def version_constraint @version_constraint end |
Class Method Details
.included(base) ⇒ Object
62 63 64 |
# File 'lib/berkshelf/location.rb', line 62 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.
95 96 97 98 99 |
# File 'lib/berkshelf/location.rb', line 95 def init(name, constraint, = {}) klass = () klass.new(name, constraint, ) end |
Instance Method Details
#download(destination) ⇒ Berkshelf::CachedCookbook
133 134 135 |
# File 'lib/berkshelf/location.rb', line 133 def download(destination) raise AbstractFunction end |
#initialize(name, version_constraint, options = {}) ⇒ Object
124 125 126 127 128 |
# File 'lib/berkshelf/location.rb', line 124 def initialize(name, version_constraint, = {}) @name = name @version_constraint = version_constraint @downloaded_status = false end |
#to_hash ⇒ Object
159 160 161 162 163 |
# File 'lib/berkshelf/location.rb', line 159 def to_hash { type: self.class.location_key } end |
#to_json(options = {}) ⇒ Object
165 166 167 |
# File 'lib/berkshelf/location.rb', line 165 def to_json( = {}) JSON.pretty_generate(to_hash, ) end |
#validate_cached(cached_cookbook) ⇒ Boolean
Change MismatchedCookbookName to raise instead of warn
Ensure the retrieved CachedCookbook is valid
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/berkshelf/location.rb', line 147 def validate_cached(cached_cookbook) unless version_constraint.satisfies?(cached_cookbook.version) raise CookbookValidationFailure.new(self, cached_cookbook) end unless self.name == cached_cookbook.cookbook_name Berkshelf.ui.warn(MismatchedCookbookName.new(self, cached_cookbook).to_s) end true end |