lib/nanoc/base/source_data/item.rb in nanoc-3.6.7 vs lib/nanoc/base/source_data/item.rb in nanoc-3.6.8

- old
+ new

@@ -65,15 +65,15 @@ # modified. Deprecated; pass the modification time as the `:mtime` # attribute instead. # # @option params [Symbol, nil] :binary (true) Whether or not this item is # binary - def initialize(raw_content_or_raw_filename, attributes, identifier, params=nil) + def initialize(raw_content_or_raw_filename, attributes, identifier, params = nil) # Parse params params ||= {} params = { :mtime => params } if params.is_a?(Time) - params[:binary] = false unless params.has_key?(:binary) + params[:binary] = false unless params.key?(:binary) if raw_content_or_raw_filename.nil? raise "attempted to create an item with no content/filename (identifier #{identifier})" end @@ -124,11 +124,11 @@ # @return [String] The compiled content of the given rep (or the default # rep if no rep is specified) at the given snapshot (or the default # snapshot if no snapshot is specified) # # @see ItemRep#compiled_content - def compiled_content(params={}) + def compiled_content(params = {}) # Get rep rep_name = params[:rep] || :default rep = reps.find { |r| r.name == rep_name } if rep.nil? raise Nanoc::Errors::Generic, @@ -146,11 +146,11 @@ # from which the path should be fetched. By default, the path will be # fetched from the default representation. # # @return [String] The path of the given rep ( or the default rep if no # rep is specified) - def path(params={}) + def path(params = {}) rep_name = params[:rep] || :default # Get rep rep = reps.find { |r| r.name == rep_name } if rep.nil? @@ -224,11 +224,11 @@ # # @api private # # @return [Object] An unique reference to this object def reference - [ type, self.identifier ] + [ type, identifier ] end # Prevents all further modifications to its attributes. # # @return [void] @@ -239,39 +239,40 @@ raw_filename.freeze if raw_filename raw_content.freeze if raw_content end def inspect - "<#{self.class} identifier=\"#{self.identifier}\" binary?=#{self.binary?}>" + "<#{self.class} identifier=\"#{identifier}\" binary?=#{self.binary?}>" end # @return [String] The checksum for this object. If its contents change, # the checksum will change as well. def checksum - content_checksum = if binary? - if File.exist?(raw_filename) - Pathname.new(raw_filename).checksum + content_checksum = + if binary? + if File.exist?(raw_filename) + Pathname.new(raw_filename).checksum + else + ''.checksum + end else - ''.checksum + @raw_content.checksum end - else - @raw_content.checksum - end attributes = @attributes.dup attributes.delete(:file) attributes_checksum = attributes.checksum content_checksum + ',' + attributes_checksum end memoize :checksum def hash - self.class.hash ^ self.identifier.hash + self.class.hash ^ identifier.hash end def eql?(other) - self.class == other.class && self.identifier == other.identifier + self.class == other.class && identifier == other.identifier end def ==(other) self.eql?(other) end