Sha256: af3c025138b045a9362a99420558cf7ea6c53211b06476944a1885369b76dd87

Contents?: true

Size: 868 Bytes

Versions: 6

Compression:

Stored size: 868 Bytes

Contents

module Pageflow
  class UsedFile < SimpleDelegator
    def initialize(file, usage = nil)
      super(file)
      @file = file
      @usage = usage || file.usages.first
    end

    def configuration
      @usage.configuration
    end

    def update!(attributes)
      super(attributes.except(:configuration))
      @usage.update!(attributes.slice(:configuration))
    end

    def usage_id
      @usage.id
    end

    def perma_id
      @usage.perma_id
    end

    def cache_key
      [@file.cache_key, @usage.cache_key].join('-')
    end

    def cache_key_with_version
      [@file.cache_key_with_version, @usage.cache_key_with_version].join('-')
    end

    # Not delegated by default. Required to allow using instances in
    # Active Record conditions.

    def is_a?(klass)
      @file.is_a?(klass)
    end

    def class
      @file.class
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pageflow-17.0.4 app/models/pageflow/used_file.rb
pageflow-17.0.3 app/models/pageflow/used_file.rb
pageflow-17.0.2 app/models/pageflow/used_file.rb
pageflow-17.0.1 app/models/pageflow/used_file.rb
pageflow-17.0.0 app/models/pageflow/used_file.rb
pageflow-16.2.0 app/models/pageflow/used_file.rb