Sha256: 313e9ecf595689f21ca553f455de653ac4840b683124765bd081284f9ba92658

Contents?: true

Size: 744 Bytes

Versions: 10

Compression:

Stored size: 744 Bytes

Contents

module Nanoc

  # Nanoc::AssetProxy is a proxy object for an asset (Nanoc::Asset).
  class AssetProxy < Proxy

    # Requests the asset 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

      if real_key == :mtime
        @obj.mtime
      elsif real_key == :path # backward compatibility
        @obj.reps.find { |r| r.name == :default }.web_path
      else
        super(key)
      end
    end

    # Returns the asset representation with the given name.
    def reps(name)
      rep = @obj.reps.find { |r| r.name == name }
      rep.nil? ? nil : rep.to_proxy
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
nanoc-2.1.2 lib/nanoc/base/proxies/asset_proxy.rb
nanoc-2.1.6 lib/nanoc/base/proxies/asset_proxy.rb
nanoc-2.2 lib/nanoc/base/proxies/asset_proxy.rb
nanoc-2.2.1 lib/nanoc/base/proxies/asset_proxy.rb
nanoc-2.2.2 lib/nanoc/base/proxies/asset_proxy.rb
nanoc-2.1 lib/nanoc/base/proxies/asset_proxy.rb
nanoc-2.1.1 lib/nanoc/base/proxies/asset_proxy.rb
nanoc-2.1.3 lib/nanoc/base/proxies/asset_proxy.rb
nanoc-2.1.4 lib/nanoc/base/proxies/asset_proxy.rb
nanoc-2.1.5 lib/nanoc/base/proxies/asset_proxy.rb