Class: Nanoc::Core::Document
- Inherits:
-
Object
- Object
- Nanoc::Core::Document
show all
- Includes:
- ContractsSupport
- Defined in:
- lib/nanoc/core/document.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
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.
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# 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
@hash = [self.class, identifier].hash
reference
end
|
Instance Attribute Details
#attributes_checksum_data ⇒ String?
21
22
23
|
# File 'lib/nanoc/core/document.rb', line 21
def attributes_checksum_data
@attributes_checksum_data
end
|
#checksum_data ⇒ String?
15
16
17
|
# File 'lib/nanoc/core/document.rb', line 15
def checksum_data
@checksum_data
end
|
9
10
11
|
# File 'lib/nanoc/core/document.rb', line 9
def content
@content
end
|
#content_checksum_data ⇒ String?
18
19
20
|
# File 'lib/nanoc/core/document.rb', line 18
def content_checksum_data
@content_checksum_data
end
|
12
13
14
|
# File 'lib/nanoc/core/document.rb', line 12
def identifier
@identifier
end
|
Instance Method Details
#==(other) ⇒ Object
118
119
120
|
# File 'lib/nanoc/core/document.rb', line 118
def ==(other)
other.respond_to?(:identifier) && identifier == other.identifier
end
|
#attributes ⇒ Hash
59
60
61
|
# File 'lib/nanoc/core/document.rb', line 59
def attributes
@attributes.value
end
|
#eql?(other) ⇒ Boolean
123
124
125
|
# File 'lib/nanoc/core/document.rb', line 123
def eql?(other)
other.is_a?(self.class) && identifier == other.identifier
end
|
#freeze ⇒ void
This method returns an undefined value.
65
66
67
68
69
70
|
# File 'lib/nanoc/core/document.rb', line 65
def freeze
super
@content.freeze
@attributes.freeze
self
end
|
#hash ⇒ Object
113
114
115
|
# File 'lib/nanoc/core/document.rb', line 113
def hash
@hash
end
|
#inspect ⇒ Object
108
109
110
|
# File 'lib/nanoc/core/document.rb', line 108
def inspect
"<#{self.class} identifier=\"#{identifier}\">"
end
|
#reference ⇒ Object
Returns Unique reference to this object.
83
84
85
|
# File 'lib/nanoc/core/document.rb', line 83
def reference
raise NotImplementedError
end
|
#set_attribute(key, value) ⇒ Object
100
101
102
103
104
105
|
# File 'lib/nanoc/core/document.rb', line 100
def set_attribute(key, value)
attributes[key] = value
@checksum_data = nil
@attributes_checksum_data = nil
end
|
#with_identifier_prefix(prefix) ⇒ Object
73
74
75
76
77
|
# File 'lib/nanoc/core/document.rb', line 73
def with_identifier_prefix(prefix)
other = dup
other.identifier = @identifier.prefix(prefix)
other
end
|