Sha256: ab3f34daa14b89fb30b4953dc5563bd4f14bea3a57955e0a06162fbe5e9add58
Contents?: true
Size: 1.76 KB
Versions: 5
Compression:
Stored size: 1.76 KB
Contents
module Nanoc module DocumentViewMixin # @api private NONE = Object.new.freeze # @api private def initialize(document, context) super(context) @document = document end # @api private def unwrap @document end # @see Object#== def ==(other) other.respond_to?(:identifier) && identifier == other.identifier end alias eql? == # @see Object#hash def hash self.class.hash ^ identifier.hash end # @return [Nanoc::Identifier] def identifier unwrap.identifier end # @see Hash#[] def [](key) Nanoc::Int::NotificationCenter.post(:visit_started, unwrap) Nanoc::Int::NotificationCenter.post(:visit_ended, unwrap) unwrap.attributes[key] end # @return [Hash] def attributes Nanoc::Int::NotificationCenter.post(:visit_started, unwrap) Nanoc::Int::NotificationCenter.post(:visit_ended, unwrap) unwrap.attributes end # @see Hash#fetch 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 # @see Hash#key? def key?(key) Nanoc::Int::NotificationCenter.post(:visit_started, unwrap) Nanoc::Int::NotificationCenter.post(:visit_ended, unwrap) unwrap.attributes.key?(key) end # @api private def reference unwrap.reference end # @api private def raw_content unwrap.content.string end end end
Version data entries
5 entries across 5 versions & 1 rubygems