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#==


20
21
22
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 20

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

#[](key) ⇒ Object

See Also:

  • Hash#[]


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

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

#attributesHash

Returns:

  • (Hash)


46
47
48
49
50
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 46

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Object#eql?


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

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

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

See Also:

  • Hash#fetch


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

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

  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


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

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

#identifierNanoc::Identifier

Returns:



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

def identifier
  unwrap.identifier
end

#inspectObject



84
85
86
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 84

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Hash#key?


68
69
70
71
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 68

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