Sha256: 888bb4fa1420f7ccc3bc0f09d03957b21582c0909964bc54900920703490df7a

Contents?: true

Size: 882 Bytes

Versions: 1

Compression:

Stored size: 882 Bytes

Contents

module Associo
  # Proxy for the Attached file.
  class AttachmentProxy
    def initialize(instance, name)
      @instance = instance
      @name     = name
    end

    def id
      @instance.send "#{@name}_id"
    end

    def name
      @instance.send "#{@name}_name"
    end

    def size
      @instance.send "#{@name}_size"
    end

    def type
      @instance.send "#{@name}_type"
    end

    def chunk_size
      @instance.send "#{@name}_chunk_size"
    end

    def nil?
      !@instance.send("#{@name}?")
    end

    alias blank? nil?

    def grid_io
      @grid_io ||= @instance.grid.get(id)
    end

    def method_missing(method, *args, &block)
      if grid_io.respond_to? method.to_s
        grid_io.send(method, *args, &block)
      else
        super
      end
    end

    def respond_to_missing?(method, include_private = false)
      super
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
associo-0.1.0 lib/associo/attachment_proxy.rb