Sha256: 7c94ff7369b71d8483d166db59691a0e833581a829c7e496a56b6eb5e5e456a8

Contents?: true

Size: 1.4 KB

Versions: 14

Compression:

Stored size: 1.4 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
          return result
        end
        false 
      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

14 entries across 14 versions & 1 rubygems

Version Path
trackman-0.6.9 lib/trackman/assets/remote_asset.rb
trackman-0.6.8 lib/trackman/assets/remote_asset.rb
trackman-0.6.7 lib/trackman/assets/remote_asset.rb
trackman-0.6.6 lib/trackman/assets/remote_asset.rb
trackman-0.6.5 lib/trackman/assets/remote_asset.rb
trackman-0.6.4 lib/trackman/assets/remote_asset.rb
trackman-0.6.3 lib/trackman/assets/remote_asset.rb
trackman-0.6.2 lib/trackman/assets/remote_asset.rb
trackman-0.6.1 lib/trackman/assets/remote_asset.rb
trackman-0.6.0 lib/trackman/assets/remote_asset.rb
trackman-0.5.8 lib/trackman/assets/remote_asset.rb
trackman-0.5.7 lib/trackman/assets/remote_asset.rb
trackman-0.5.6 lib/trackman/assets/remote_asset.rb
trackman-0.5.5 lib/trackman/assets/remote_asset.rb