Module: Nanoc::DocumentViewMixin

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

Constant Summary

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

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#[]


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

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

#attributesHash

Returns:

  • (Hash)


40
41
42
43
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 40

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

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

See Also:

  • Hash#fetch


46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 46

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


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

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

#identifierNanoc::Identifier

Returns:



29
30
31
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 29

def identifier
  unwrap.identifier
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Hash#key?


61
62
63
64
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 61

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