Sha256: a916a469ee0cd54034c9572ebef92ee82ed1ffa44c931568c365391132dcf77a

Contents?: true

Size: 1.6 KB

Versions: 12

Compression:

Stored size: 1.6 KB

Contents

module RailsConnector

  # A binary containing the blob data of a Content or CMS management
  # data of Attribute (fields), ObjClass (object classes), for example.
  class Blob < CmsBaseModel
    self.primary_key = "blob_name"

    class << self
      # Does not retrieve the column blob_data.
      def find_with_excluded_blob_data(*args)
        args << Hash.new unless Hash === args.last
        args.last[:select] = 'blob_name, blob_length'
        find_without_excluded_blob_data(*args)
      end

      alias_method_chain :find, :excluded_blob_data
    end

    def length
      blob_length
    end

    def data
      @data ||= self.class.find_without_excluded_blob_data(id).blob_data
    end

    def path_of_stored_data(use_cached_file_if_older_than = Time.now)
      store_data if !File.exists?(path) || use_cached_file_if_older_than > File.mtime(path)
      path
    end

    def self.cache_dir
      Configuration.blob_cache_dir || File.join(Rails.root, %w(tmp cache))
    end

    def self.initialize_blob_streaming_for(adapter_name)
      # Redefines store_data:
      case adapter_name
      when /mysql/i:
        require "rails_connector/blob_mysql"
        include BlobMysql
      when /oracle/i:
        require "rails_connector/blob_oracle"
        include BlobOracle
      end
    end

    private

    def path
      "#{Blob.cache_dir}/#{id}"
    end

    def store_data
      store_data_atomically do |f|
        f << data
      end
    end

    def store_data_atomically(&block)
      tmp_file = "#{path}.#{Process.pid}"
      File.open(tmp_file, "w", &block)
      File.rename(tmp_file, path)
    end
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
infopark_fiona_connector-6.8.0.539.93842523 lib/rails_connector/blob.rb
infopark_fiona_connector-6.8.0.529.114081979 lib/rails_connector/blob.rb
infopark_fiona_connector-6.8.0.518.30999728 lib/rails_connector/blob.rb
infopark_fiona_connector-6.8.0.515.34928522 lib/rails_connector/blob.rb
infopark_fiona_connector-6.8.0.498.46559598 lib/rails_connector/blob.rb
infopark_fiona_connector-6.8.0.480.261594408 lib/rails_connector/blob.rb
infopark_fiona_connector-6.8.0.444.171626367 lib/rails_connector/blob.rb
infopark_fiona_connector-6.8.0.406.131718077 lib/rails_connector/blob.rb
infopark_fiona_connector-6.8.0.356.19698103 lib/rails_connector/blob.rb
infopark_fiona_connector-6.8.0.348.160665197 lib/rails_connector/blob.rb
infopark_fiona_connector-6.8.0.328.4a753fc lib/rails_connector/blob.rb
infopark_fiona_connector-6.8.0.322.c003f11 lib/rails_connector/blob.rb