Sha256: 1ff19f738cf524329b5e28fe75de9f63edd540cbefae1883ba9d5383bf85dae9

Contents?: true

Size: 958 Bytes

Versions: 1

Compression:

Stored size: 958 Bytes

Contents

module Progstr
  module Filer
    class Attachment
      attr_accessor :id, :attribute, :file

      @@id_generator = ::UUID.new

      class EmptyAttachment
        def empty?
          true
        end
      end

      def self.empty
        EmptyAttachment.new
      end

      def self.from_file(attribute, file)
        result = Attachment.new
        result.id = generate_id
        result.attribute = attribute
        result.file = file
        result
      end

      def self.generate_id
        uuid = @@id_generator.generate
        uuid.gsub("-", "")
      end

      def self.from_id(attribute, id)
        result = Attachment.new
        result.id = id
        result.attribute = attribute
        result
      end

      def empty?
        false
      end

      def url
        if !empty?
          "#{Progstr::Filer.url_prefix}files/data/#{Progstr::Filer.access_key}/#{id}"
        else
          ""
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
progstr-filer-0.8.0 lib/filer/attachment.rb