Sha256: 4b1ae279d4936bc6948542fd1b1387fdf950c7dd92bd89808df0cec86f55b919

Contents?: true

Size: 1.12 KB

Versions: 22

Compression:

Stored size: 1.12 KB

Contents

module Bulldog
  module Attachment
    def self.types_to_classes  #:nodoc:
      @types_to_classes ||= {}
    end
  end
end

require 'bulldog/attachment/maybe'
require 'bulldog/attachment/has_dimensions'
require 'bulldog/attachment/base'
require 'bulldog/attachment/none'
require 'bulldog/attachment/image'
require 'bulldog/attachment/video'
require 'bulldog/attachment/pdf'
require 'bulldog/attachment/unknown'

module Bulldog
  module Attachment
    #
    # Return a new attachment of the specified type.
    #
    # If +type+ is nil, then the returned attachment will be None if
    # the stream is nil, or Unknown otherwise.
    #
    def self.of_type(type, record, name, stream)
      if type.nil?
        klass = stream ? Unknown : None
      else
        klass = class_from_type(type)
      end
      klass.new(record, name, stream)
    end

    #
    # Return a None attachment for the given record and name.
    #
    def self.none(record, name)
      None.new(record, name, nil)
    end

    #
    # Return the class corresponding to the given type.
    #
    def self.class_from_type(type)
      types_to_classes[type]
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
bulldog-0.2.4 lib/bulldog/attachment.rb
bulldog-0.2.3 lib/bulldog/attachment.rb
bulldog-0.2.2 lib/bulldog/attachment.rb
bulldog-0.2.1 lib/bulldog/attachment.rb
bulldog-0.2.0 lib/bulldog/attachment.rb
bulldog-0.1.1 lib/bulldog/attachment.rb
bulldog-0.1.0 lib/bulldog/attachment.rb
bulldog-0.0.15 lib/bulldog/attachment.rb
bulldog-0.0.14 lib/bulldog/attachment.rb
bulldog-0.0.13 lib/bulldog/attachment.rb
bulldog-0.0.12 lib/bulldog/attachment.rb
bulldog-0.0.11 lib/bulldog/attachment.rb
bulldog-0.0.10 lib/bulldog/attachment.rb
bulldog-0.0.9 lib/bulldog/attachment.rb
bulldog-0.0.8 lib/bulldog/attachment.rb
bulldog-0.0.7 lib/bulldog/attachment.rb
bulldog-0.0.6 lib/bulldog/attachment.rb
bulldog-0.0.5 lib/bulldog/attachment.rb
bulldog-0.0.3 lib/bulldog/attachment.rb
bulldog-0.0.4 lib/bulldog/attachment.rb