lib/chef-api/resources/base.rb in chef-api-0.10.0 vs lib/chef-api/resources/base.rb in chef-api-0.10.2

- old
+ new

@@ -11,11 +11,11 @@ # # @param [String] path # the path to the file on disk # def from_file(path) - raise Error::AbstractMethod.new(method: 'Resource::Base#from_file') + raise Error::AbstractMethod.new(method: "Resource::Base#from_file") end # # @todo doc # @@ -76,11 +76,11 @@ # @example Create an association with custom configuration # # has_many :environments, class_name: 'Environment' # def has_many(method, options = {}) - class_name = options[:class_name] || "Resource::#{Util.camelize(method).sub(/s$/, '')}" + class_name = options[:class_name] || "Resource::#{Util.camelize(method).sub(/s$/, "")}" rest_endpoint = options[:rest_endpoint] || method class_eval <<-EOH, __FILE__, __LINE__ + 1 def #{method} associations[:#{method}] ||= @@ -225,11 +225,11 @@ # the list of prefix options (for nested resources) # @return [Array<Base>] # an array containing the list of resources that were deleted # def destroy_all(prefix = {}) - map { |resource| resource.destroy } + map(&:destroy) end # # Fetch a single resource in the remote collection. # @@ -402,12 +402,12 @@ # # @return [Resource::Base] # an instance of the resource represented by this JSON # def from_json(response, prefix = {}) - response.delete('json_class') - response.delete('chef_type') + response.delete("json_class") + response.delete("chef_type") new(response, prefix) end # @@ -430,11 +430,11 @@ # Bacon.inspect #=> "Resource::Bacon(id, description, ...)" # # @return [String] # def inspect - "#{classname}(#{schema.attributes.keys.join(', ')})" + "#{classname}(#{schema.attributes.keys.join(", ")})" end # # The name for this resource, minus the parent module. # @@ -442,11 +442,11 @@ # classname #=> Resource::Bacon # # @return [String] # def classname - name.split('::')[1..-1].join('::') + name.split("::")[1..-1].join("::") end # # The type of this resource. # @@ -454,11 +454,11 @@ # bacon # # @return [String] # def type - Util.underscore(name.split('::').last).gsub('_', ' ') + Util.underscore(name.split("::").last).gsub("_", " ") end # # The full collection list. # @@ -480,11 +480,11 @@ # # @return [String] # the path to the resource # def resource_path(id, prefix = {}) - [expanded_collection_path(prefix), id].join('/') + [expanded_collection_path(prefix), id].join("/") end # # Expand the collection path, "interpolating" any parameters. This syntax # is heavily borrowed from Rails and it will make more sense by looking @@ -503,28 +503,28 @@ # @return [String] # the "interpolated" URL string # def expanded_collection_path(prefix = {}) collection_path.gsub(/:\w+/) do |param| - key = param.delete(':') + key = param.delete(":") value = prefix[key] || prefix[key.to_sym] if value.nil? raise Error::MissingURLParameter.new(param: key) end URI.escape(value) - end.sub(/^\//, '') # Remove leading slash + end.sub(%r{^/}, "") # Remove leading slash end # # The current connection object. # # @return [ChefAPI::Connection] # def connection - Thread.current['chefapi.connection'] || ChefAPI.connection + Thread.current["chefapi.connection"] || ChefAPI.connection end end # # The list of associations. @@ -618,11 +618,11 @@ # # @return [Boolean] # true if the attribute exists, false otherwise # def attribute?(key) - _attributes.has_key?(key.to_sym) + _attributes.key?(key.to_sym) end # # Determine if this current resource is protected. Resources may be # protected by name or by a Proc. A protected resource is one that should @@ -631,16 +631,16 @@ # # @return [Boolean] # def protected? @protected ||= self.class.protected_resources.any? do |thing| - if thing.is_a?(Proc) - thing.call(self) - else - id == thing - end - end + if thing.is_a?(Proc) + thing.call(self) + else + id == thing + end + end end # # Reload (or reset) this object using the values currently stored on the # remote server. This method will also clear any cached collection proxies @@ -773,11 +773,11 @@ # anything other than true because an exception is raised if validations # fail # def validate! unless valid? - sentence = errors.full_messages.join(', ') + sentence = errors.full_messages.join(", ") raise Error::InvalidResource.new(errors: sentence) end true end @@ -894,11 +894,11 @@ # the attribute to check ignorance # # @return [Boolean] # def ignore_attribute?(key) - @schema.ignored_attributes.has_key?(key.to_sym) + @schema.ignored_attributes.key?(key.to_sym) end # # The collection of errors on the resource. # @@ -952,9 +952,9 @@ else "#{key}: #{value.inspect}" end end - "#<#{self.class.classname} #{attrs.join(', ')}>" + "#<#{self.class.classname} #{attrs.join(", ")}>" end end end