Module: Nanoc::DocumentViewMixin

Included in:
ItemWithoutRepsView, LayoutView
Defined in:
lib/nanoc/base/views/mixins/document_view_mixin.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object

See Also:

  • Object#==


18
19
20
# File 'lib/nanoc/base/views/mixins/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/base/views/mixins/document_view_mixin.rb', line 38

def [](key)
  @context.dependency_tracker.bounce(unwrap)
  unwrap.attributes[key]
end

#attributesHash

Returns:

  • (Hash)


44
45
46
47
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 44

def attributes
  @context.dependency_tracker.bounce(unwrap)
  unwrap.attributes
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Object#eql?


23
24
25
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 23

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

#fetch(key, fallback = NONE, &_block) ⇒ Object

See Also:

  • Hash#fetch


50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 50

def fetch(key, fallback = NONE, &_block)
  @context.dependency_tracker.bounce(unwrap)

  if unwrap.attributes.key?(key)
    unwrap.attributes[key]
  elsif !fallback.equal?(NONE)
    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/base/views/mixins/document_view_mixin.rb', line 28

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

#identifierNanoc::Identifier

Returns:



33
34
35
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 33

def identifier
  unwrap.identifier
end

#inspectObject



80
81
82
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 80

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Hash#key?


65
66
67
68
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 65

def key?(key)
  @context.dependency_tracker.bounce(unwrap)
  unwrap.attributes.key?(key)
end