Module: Nanoc::Core::DocumentViewMixin

Included in:
BasicItemView, LayoutView
Defined in:
lib/nanoc/core/document_view_mixin.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object

See Also:

  • Object#==


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

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

#[](key) ⇒ Object

See Also:

  • Hash#[]


38
39
40
41
# File 'lib/nanoc/core/document_view_mixin.rb', line 38

def [](key)
  @context.dependency_tracker.bounce(_unwrap, attributes: [key])
  _unwrap.attributes[key]
end

#_unwrapObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
# File 'lib/nanoc/core/document_view_mixin.rb', line 13

def _unwrap
  @document
end

#attributesHash

Returns:



44
45
46
47
48
# File 'lib/nanoc/core/document_view_mixin.rb', line 44

def attributes
  # TODO: Refine dependencies
  @context.dependency_tracker.bounce(_unwrap, attributes: true)
  _unwrap.attributes
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Object#eql?


23
24
25
# File 'lib/nanoc/core/document_view_mixin.rb', line 23

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

#fetch(key, fallback = Nanoc::Core::UNDEFINED, &_block) ⇒ Object

See Also:

  • Hash#fetch


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/nanoc/core/document_view_mixin.rb', line 51

def fetch(key, fallback = Nanoc::Core::UNDEFINED, &_block)
  @context.dependency_tracker.bounce(_unwrap, attributes: [key])

  if _unwrap.attributes.key?(key)
    _unwrap.attributes[key]
  elsif !Nanoc::Core::UNDEFINED.equal?(fallback)
    fallback
  elsif block_given?
    yield(key)
  else
    raise KeyError, "key not found: #{key.inspect}"
  end
end

#hashObject

See Also:

  • Object#hash


28
29
30
# File 'lib/nanoc/core/document_view_mixin.rb', line 28

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

#identifierNanoc::Core::Identifier



33
34
35
# File 'lib/nanoc/core/document_view_mixin.rb', line 33

def identifier
  _unwrap.identifier
end

#initialize(document, context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



7
8
9
10
# File 'lib/nanoc/core/document_view_mixin.rb', line 7

def initialize(document, context)
  super(context)
  @document = document
end

#inspectObject



82
83
84
# File 'lib/nanoc/core/document_view_mixin.rb', line 82

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Hash#key?


66
67
68
69
# File 'lib/nanoc/core/document_view_mixin.rb', line 66

def key?(key)
  @context.dependency_tracker.bounce(_unwrap, attributes: [key])
  _unwrap.attributes.key?(key)
end

#raw_contentObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



77
78
79
80
# File 'lib/nanoc/core/document_view_mixin.rb', line 77

def raw_content
  @context.dependency_tracker.bounce(_unwrap, raw_content: true)
  _unwrap.content.string
end

#referenceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



72
73
74
# File 'lib/nanoc/core/document_view_mixin.rb', line 72

def reference
  _unwrap.reference
end