lib/nanoc3/base/source_data/item.rb in nanoc3-3.2.0a4 vs lib/nanoc3/base/source_data/item.rb in nanoc3-3.2.0b1
- old
+ new
@@ -164,20 +164,23 @@
Nanoc3::NotificationCenter.post(:visit_ended, self)
# Get captured content (hax)
# TODO [in nanoc 4.0] remove me
if key.to_s =~ /^content_for_(.*)$/
+ @@_content_for_warning_issued ||= false
+ @@_Nanoc3_Helpers_Capturing_included ||= false
+
# Warn
- unless @_content_for_warning_issued
+ unless @@_content_for_warning_issued
warn 'WARNING: Accessing captured content should happen using the #content_for method defined in the Capturing helper instead of using item[:content_for_something]. The latter way of accessing captured content will be removed in nanoc 4.0.'
- @_content_for_warning_issued = true
+ @@_content_for_warning_issued = true
end
# Include capturing helper if necessary
- unless @_Nanoc3_Helpers_Capturing_included
+ unless @@_Nanoc3_Helpers_Capturing_included
self.class.send(:include, ::Nanoc3::Helpers::Capturing)
- @_Nanoc3_Helpers_Capturing_included = true
+ @@_Nanoc3_Helpers_Capturing_included = true
end
# Get content
return content_for(self, $1.to_sym)
end
@@ -231,20 +234,59 @@
def inspect
"<#{self.class}:0x#{self.object_id.to_s(16)} identifier=#{self.identifier} binary?=#{self.binary?}>"
end
- # TODO document
+ # @return [String] The checksum for this object. If its contents change,
+ # the checksum will change as well.
def checksum
- if binary?
- Pathname.new(raw_filename).checksum
+ content_checksum = if binary?
+ if File.exist?(raw_filename)
+ Pathname.new(raw_filename).checksum
+ else
+ ''.checksum
+ end
else
- attributes = @attributes.dup
- attributes.delete(:file)
- @raw_content.checksum + ',' + attributes.checksum
+ @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
+ end
+
+ def eql?(other)
+ self.class == other.class && self.identifier == other.identifier
+ end
+
+ def ==(other)
+ self.eql?(other)
+ end
+
+ def marshal_dump
+ [
+ @is_binary,
+ @raw_filename,
+ @raw_content,
+ @attributes,
+ @identifier
+ ]
+ end
+
+ def marshal_load(source)
+ @is_binary,
+ @raw_filename,
+ @raw_content,
+ @attributes,
+ @identifier = *source
+ end
# @deprecated Access the modification time using `item[:mtime]` instead.
def mtime
self[:mtime]
end