Sha256: be09cea468e4be282c178a21b35c61c14bd10b732f7679064c9b016311718e78

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

include ActionView::Helpers::AssetTagHelper

module Uploadcare
  module Rails
    class File < Uploadcare::Api::File

      # override default to string method
      # instead of string representation of object it will return simple cdn url of a file
      def to_s
        cdn_url
      end

      # construct image tag for file
      def image with_operations=true, options={}
        if with_operations
          url = cdn_url_with_operations
        else
          url = cdn_url
        end
        
        image_tag url, options
      end

      def load_data
        super
        ::Rails.cache.write(cdn_url, self.marshal_dump) if UPLOADCARE_SETTINGS.cache_files
        self
      end
      alias_method :load, :load_data

      def load_data!
        super
        ::Rails.cache.write(cdn_url, self.marshal_dump) if UPLOADCARE_SETTINGS.cache_files
        self
      end
      alias_method :load!, :load_data!

      def to_builder
        marshal_dump
      end

      def to_json
        marshal_dump
      end

      def as_json options={}
        marshal_dump
      end

      def marshal_dump
        @table.stringify_keys
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
uploadcare-rails-1.0.5 lib/uploadcare/rails/objects/file.rb
uploadcare-rails-1.0.4 lib/uploadcare/rails/objects/file.rb
uploadcare-rails-1.0.3 lib/uploadcare/rails/objects/file.rb