Module: Berkshelf::Location::ClassMethods
- Defined in:
- lib/berkshelf/location.rb
Instance Attribute Summary collapse
-
#location_key ⇒ Symbol
readonly
Returns the location identifier key for the class.
Instance Method Summary collapse
-
#set_location_key(key) ⇒ Object
Register the location key for the including source location with CookbookSource.
-
#set_valid_options(*opts) ⇒ Object
Register a valid option or multiple options with the CookbookSource class.
-
#solve_for_constraint(constraint, versions) ⇒ Array?
Returns an array where the first element is string representing the best version for the given constraint and the second element is the URI to where the corresponding version of the Cookbook can be downloaded from.
Instance Attribute Details
#location_key ⇒ Symbol (readonly)
Returns the location identifier key for the class
11 12 13 |
# File 'lib/berkshelf/location.rb', line 11 def location_key @location_key end |
Instance Method Details
#set_location_key(key) ⇒ Object
Register the location key for the including source location with CookbookSource
16 17 18 19 |
# File 'lib/berkshelf/location.rb', line 16 def set_location_key(key) CookbookSource.add_location_key(key, self) @location_key = key end |
#set_valid_options(*opts) ⇒ Object
Register a valid option or multiple options with the CookbookSource class
24 25 26 27 28 |
# File 'lib/berkshelf/location.rb', line 24 def (*opts) Array(opts).each do |opt| CookbookSource.add_valid_option(opt) end end |
#solve_for_constraint(constraint, versions) ⇒ Array?
Returns an array where the first element is string representing the best version for the given constraint and the second element is the URI to where the corresponding version of the Cookbook can be downloaded from
@example:
constraint = Solve::Constraint.new('~> 0.101.2')
versions = {
'1.0.0' => 'http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/1_0_0',
'2.0.0' => 'http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/2_0_0'
}
subject.solve_for_constraint(versions, constraint) =>
[ '2.0.0', 'http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/2_0_0' ]
52 53 54 55 56 57 58 |
# File 'lib/berkshelf/location.rb', line 52 def solve_for_constraint(constraint, versions) version = Solve::Solver.satisfy_best(constraint, versions.keys).to_s [ version, versions[version] ] rescue Solve::Errors::NoSolutionError nil end |