Sha256: bd0e0eec178e10eb85f7e7e9c2f7a73ef6b82400377e68f0d808ae9da1aa1aa2

Contents?: true

Size: 898 Bytes

Versions: 2

Compression:

Stored size: 898 Bytes

Contents

module ActiveGit
  class DbEvent

    def initialize(file_name, working_path=nil)
      @file_name = file_name
      @working_path = working_path || ActiveGit.configuration.working_path
    end

    def synchronize(synchronizer)
      raise 'Must implement in subclass'
    end

    private

    def model
      @model ||= Inflector.model(@file_name, @working_path)
    end

    def model_id
      Inflector.model_id @file_name
    end

    def data
      json = File.open(@file_name, 'r') { |f| f.readlines.join("\n") }
      model.from_json(json)
    end

    def create(synchronizer)
      synchronizer.bulk_insert data
    end

    def delete(synchronizer)
      synchronizer.define_job do
        ActiveGit.configuration.logger.debug "[ActiveGit] Deleting #{model.model_name} #{model_id}"
        record = model.find_by_id(model_id)
        record.delete if record
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_git-0.0.6 lib/active_git/events/db_event.rb
active_git-0.0.5 lib/active_git/events/db_event.rb