Class: Nanoc::Core::Document

Inherits:
Object
  • Object
show all
Includes:
ContractsSupport
Defined in:
lib/nanoc/core/document.rb

Direct Known Subclasses

Item, Layout

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

Constructor Details

#initialize(content, attributes, identifier, checksum_data: nil, content_checksum_data: nil, attributes_checksum_data: nil) ⇒ Document

Returns a new instance of Document.

Parameters:



44
45
46
47
48
49
50
51
52
# File 'lib/nanoc/core/document.rb', line 44

def initialize(content, attributes, identifier, checksum_data: nil, content_checksum_data: nil, attributes_checksum_data: nil)
  @content = Nanoc::Core::Content.create(content)
  @attributes = Nanoc::Core::LazyValue.new(attributes).map(&:__nanoc_symbolize_keys_recursively)
  @identifier = Nanoc::Core::Identifier.from(identifier)

  @checksum_data = checksum_data
  @content_checksum_data = content_checksum_data
  @attributes_checksum_data = attributes_checksum_data
end

Instance Attribute Details

#attributes_checksum_dataString?

Returns:



21
22
23
# File 'lib/nanoc/core/document.rb', line 21

def attributes_checksum_data
  @attributes_checksum_data
end

#checksum_dataString?

Returns:



15
16
17
# File 'lib/nanoc/core/document.rb', line 15

def checksum_data
  @checksum_data
end

#contentNanoc::Core::Content



9
10
11
# File 'lib/nanoc/core/document.rb', line 9

def content
  @content
end

#content_checksum_dataString?

Returns:



18
19
20
# File 'lib/nanoc/core/document.rb', line 18

def content_checksum_data
  @content_checksum_data
end

#identifierNanoc::Core::Identifier



12
13
14
# File 'lib/nanoc/core/document.rb', line 12

def identifier
  @identifier
end

Instance Method Details

#==(other) ⇒ Object



114
115
116
# File 'lib/nanoc/core/document.rb', line 114

def ==(other)
  other.respond_to?(:identifier) && identifier == other.identifier
end

#attributesHash

Returns:



55
56
57
# File 'lib/nanoc/core/document.rb', line 55

def attributes
  @attributes.value
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/nanoc/core/document.rb', line 119

def eql?(other)
  other.is_a?(self.class) && identifier == other.identifier
end

#freezevoid

This method returns an undefined value.



61
62
63
64
65
66
# File 'lib/nanoc/core/document.rb', line 61

def freeze
  super
  @content.freeze
  @attributes.freeze
  self
end

#hashObject



109
110
111
# File 'lib/nanoc/core/document.rb', line 109

def hash
  self.class.hash ^ identifier.hash
end

#inspectObject



104
105
106
# File 'lib/nanoc/core/document.rb', line 104

def inspect
  "<#{self.class} identifier=\"#{identifier}\">"
end

#referenceObject

This method is abstract.

Returns Unique reference to this object.

Returns:

  • Unique reference to this object

Raises:

  • (NotImplementedError)


79
80
81
# File 'lib/nanoc/core/document.rb', line 79

def reference
  raise NotImplementedError
end

#set_attribute(key, value) ⇒ Object



96
97
98
99
100
101
# File 'lib/nanoc/core/document.rb', line 96

def set_attribute(key, value)
  attributes[key] = value

  @checksum_data = nil
  @attributes_checksum_data = nil
end

#with_identifier_prefix(prefix) ⇒ Object



69
70
71
72
73
# File 'lib/nanoc/core/document.rb', line 69

def with_identifier_prefix(prefix)
  other = dup
  other.identifier = @identifier.prefix(prefix)
  other
end