Sha256: f7ec410e8914fc2fcb22af49ee50f2280b2f4b71b8565c556fce1c6c1fd1f1a8

Contents?: true

Size: 1.2 KB

Versions: 17

Compression:

Stored size: 1.2 KB

Contents

require 'uri'

module Khronos
  class Storage
    autoload :Adapter, 'khronos/storage/adapter'

    def initialize(uri=ENV['KHRONOS_STORAGE'])
      raise RuntimeError.new("Please configure 'KHRONOS_STORAGE' on your environment variables.") if uri.nil?

      @adapter = Adapter.get(uri)
      self.migrate! if @adapter.name =~ /ActiveRecord/
      self.class.send(:include, @adapter)
    end

    def logger=(logger)
      #
      # Change logger current adapter's logger
      #
      raise NotImplementedMethod
    end

    def truncate!
      Schedule.delete_all
      ScheduleLog.delete_all
    end

    protected

      def migrate!
        require 'khronos/storage/adapter/activerecord/migrations/schedule'
        require 'khronos/storage/adapter/activerecord/migrations/schedule_log'

        unless ActiveRecord::Base.connection.table_exists?(:schedules)
          Adapter::ActiveRecord::CreateSchedule.up
        else
          Logger.debug "Schedules table already exists."
        end

        unless ActiveRecord::Base.connection.table_exists?(:schedule_logs)
          Adapter::ActiveRecord::CreateScheduleLog.up
        else
          Logger.debug "ScheduleLog table already exists."
        end
      end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
khronos-0.1.3 lib/khronos/storage.rb
khronos-0.1.2 lib/khronos/storage.rb
khronos-0.1.1 lib/khronos/storage.rb
khronos-0.1.0 lib/khronos/storage.rb
khronos-0.0.3.pre4 lib/khronos/storage.rb
khronos-0.0.3.pre3 lib/khronos/storage.rb
khronos-0.0.3.pre2 lib/khronos/storage.rb
khronos-0.0.3.pre1 lib/khronos/storage.rb
khronos-0.0.2 lib/khronos/storage.rb
khronos-0.0.2.pre1 lib/khronos/storage.rb
khronos-0.0.1.pre6 lib/khronos/storage.rb
khronos-0.0.1.pre5 lib/khronos/storage.rb
khronos-0.0.1.pre4 lib/khronos/storage.rb
khronos-0.0.1.pre3 lib/khronos/storage.rb
khronos-0.0.1.pre2 lib/khronos/storage.rb
khronos-0.0.1.pre1 lib/khronos/storage.rb
khronos-0.0.1 lib/khronos/storage.rb