Sha256: 82c06562720e8f2a79886d8c6d883ab306e09eb0cd44ad513da5d5c3f18ada7f

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

require 'rest-client'
require 'uri'
 
module Trackman
  module Assets
    class RemoteAsset < Asset
      extend RemoteAssetFactory
      include Persistence::Remote

      attr_reader :id

      def initialize attributes = {}
        ensure_config
        super

        @id = attributes[:id]
        @file_hash = attributes[:file_hash]
      end
      
      def validate_path?
        false
      end

      def ==(other)
        result = super
        if result
          if other.is_a? RemoteAsset
            result = other.id == id && other.file_hash == file_hash 
          end
        end
        result 
      end

      private
        def build_params
          { :asset => { :virtual_path => virtual_path.to_s, :path => path.to_s, :file => AssetIO.new(path.to_s, data) }, :multipart => true }
        end 
        def ensure_config
          raise Errors::ConfigNotFoundError, "The config TRACKMAN_URL is missing." if self.class.server_url.nil?      
        end
        class AssetIO < StringIO
          attr_accessor :filepath

          def initialize(*args)
            super(*args[1..-1])
            @filepath = args[0]
          end

          def original_filename
            File.basename(filepath)
          end
           def content_type
            MIME::Types.type_for(path).to_s
          end
          def path
            @filepath
          end
        end
    end 
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trackman-0.6.18 lib/trackman/assets/remote_asset.rb
trackman-0.6.17 lib/trackman/assets/remote_asset.rb
trackman-0.6.16 lib/trackman/assets/remote_asset.rb
trackman-0.6.15 lib/trackman/assets/remote_asset.rb