Module: Nanoc::DocumentViewMixin
- Included in:
- ItemWithoutRepsView, LayoutView
- Defined in:
- lib/nanoc/base/views/mixins/document_view_mixin.rb
Constant Summary
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
-
#[](key) ⇒ Object
-
#attributes ⇒ Hash
-
#fetch(key, fallback = NONE, &_block) ⇒ Object
-
#hash ⇒ Object
-
#identifier ⇒ Nanoc::Identifier
-
#key?(key) ⇒ Boolean
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
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
34 35 36 37 38 39 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 34 def [](key) Nanoc::Int::NotificationCenter.post(:visit_started, unwrap) Nanoc::Int::NotificationCenter.post(:visit_ended, unwrap) unwrap.attributes[key] end |
#attributes ⇒ Hash
42 43 44 45 46 47 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 42 def attributes Nanoc::Int::NotificationCenter.post(:visit_started, unwrap) Nanoc::Int::NotificationCenter.post(:visit_ended, unwrap) unwrap.attributes end |
#fetch(key, fallback = NONE, &_block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 50 def fetch(key, fallback = NONE, &_block) Nanoc::Int::NotificationCenter.post(:visit_started, unwrap) Nanoc::Int::NotificationCenter.post(:visit_ended, 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 |
#hash ⇒ Object
24 25 26 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 24 def hash self.class.hash ^ identifier.hash end |
#identifier ⇒ Nanoc::Identifier
29 30 31 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 29 def identifier unwrap.identifier end |
#key?(key) ⇒ Boolean
66 67 68 69 70 71 |
# File 'lib/nanoc/base/views/mixins/document_view_mixin.rb', line 66 def key?(key) Nanoc::Int::NotificationCenter.post(:visit_started, unwrap) Nanoc::Int::NotificationCenter.post(:visit_ended, unwrap) unwrap.attributes.key?(key) end |