Module: Berkshelf::Location::ClassMethods

Defined in:
lib/berkshelf/location.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#location_keySymbol (readonly)

Returns the location identifier key for the class

Returns:

  • (Symbol)


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

Parameters:

  • key (Symbol)


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

Parameters:

  • opts (Symbol)


24
25
26
27
28
# File 'lib/berkshelf/location.rb', line 24

def set_valid_options(*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' ]

Parameters:

  • constraint (String, Solve::Constraint)

    version constraint to solve for

  • versions (Hash)

    a hash where the keys are a string representing a cookbook version and the values are the download URL for the cookbook version.

Returns:

  • (Array, nil)


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