Sha256: 73be728fd6c742fe38402ddbc2d9c854a56f7be539c79cc9b4a8a29a688e8f04
Contents?: true
Size: 1.02 KB
Versions: 5
Compression:
Stored size: 1.02 KB
Contents
module Nanoc # Nanoc::Proxy is used when making data available to pages and layouts. # It provides an easy way to access data without the risk of accidentally # calling destructive methods. class Proxy instance_methods.each { |m| undef_method m unless m =~ /^__/ || m.to_s == 'object_id' } # Creates a proxy for the given object. def initialize(obj) @obj = obj end # Requests the attribute with the given name. +key+ can be a string or a # symbol, and it can contain a trailing question mark (which will be # stripped). def [](key) real_key = key.to_s.sub(/\?$/, '').to_sym @obj.attribute_named(real_key) end # Sets a given attribute. The use of setting an object's attributes is not # recommended but may be necessary in some cases. def []=(key, value) @obj.attributes[key.to_sym] = value end # Used for requesting attributes without accessing the proxy like a hash. def method_missing(method, *args) self[method] end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
nanoc-2.2 | lib/nanoc/base/proxy.rb |
nanoc-2.2.2 | lib/nanoc/base/proxy.rb |
nanoc-2.1.5 | lib/nanoc/base/proxy.rb |
nanoc-2.1.6 | lib/nanoc/base/proxy.rb |
nanoc-2.2.1 | lib/nanoc/base/proxy.rb |