lib/berkshelf/locations/chef_api_location.rb in berkshelf-0.4.0 vs lib/berkshelf/locations/chef_api_location.rb in berkshelf-0.5.0.rc1
- old
+ new
@@ -54,16 +54,30 @@
raise InvalidChefAPILocation, "'#{uri}' is not a valid Chef API URI."
end
true
end
+
+ # Retrieves the organization of a Chef API URI. If the URI does not contain an
+ # organization then nil will be returned.
+ #
+ # @param [String] uri
+ #
+ # @raise [InvalidChefAPILocation]
+ #
+ # @return [String, nil]
+ def extract_organization(uri)
+ validate_uri!(uri)
+
+ URI(uri).path.split('organizations/')[1]
+ end
end
include Location
- location_key :chef_api
- valid_options :node_name, :client_key
+ set_location_key :chef_api
+ set_valid_options :node_name, :client_key
attr_reader :uri
attr_reader :node_name
attr_reader :client_key
@@ -80,13 +94,13 @@
# Default: Chef::Config[:node_name]
# @option options [String] :client_key
# the filepath to the authentication key for the client
# Default: Chef::Config[:client_key]
def initialize(name, version_constraint, options = {})
- @name = name
+ @name = name
@version_constraint = version_constraint
- @downloaded_status = false
+ @downloaded_status = false
validate_options!(options)
if options[:chef_api] == :knife
begin
@@ -168,11 +182,15 @@
version = Solve.it!(graph)[name]
[ version, versions[version] ]
end
+ def to_hash
+ super.merge(value: self.uri)
+ end
+
def to_s
- "chef_api: '#{uri}'"
+ "#{self.class.location_key}: '#{uri}'"
end
private
attr_reader :rest