Sha256: 88700bdc4bdfe9c8baa955ba84448eb460b9389b3b1741c65f7d97b95f4e5f00

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 KB

Contents

require 'active_record'
require 'git_wrapper'
require 'activerecord-import'
require 'json'
require 'easy_diff'
require 'set'

require 'active_git/version'
require 'active_git/synchronizer'
require 'active_git/synchronization_error'
require 'active_git/events/db_event'
require 'active_git/events/db_create'
require 'active_git/events/db_update'
require 'active_git/events/db_delete'
require 'active_git/events/db_delete_all'
require 'active_git/events/file_event'
require 'active_git/events/file_save'
require 'active_git/events/file_delete'
require 'active_git/events/folder_remove'
require 'active_git/active_record_extension'
require 'active_git/configuration'
require 'active_git/commands'
require 'active_git/inflector'
require 'active_git/model_parser'

module ActiveGit
  extend Commands

  def self.configuration
    @configuration ||= Configuration.new
  end

  def self.configure
    yield configuration
  end

  def self.models
    @models ||= Set.new
  end

  def self.repository
    @repository = GitWrapper::Repository.new(ActiveGit.configuration.working_path) if @repository.nil? || @repository.location != ActiveGit.configuration.working_path
    @repository
  end

  def self.synchronize(*events)
    if @batch_mode
      enqueue events
    else
      Synchronizer.synchronize events
    end
  end

  def self.batch(&block)
    @batch_mode = true
    begin
      result = yield
      Synchronizer.synchronize queued_events
      result
    ensure
      @batch_mode = false
      queued_events.clear
    end
  end

  private

  def self.enqueue(*events)
    events.each { |e| queued_events << e }
  end

  def self.queued_events
    @events ||= []
  end

end

ActiveRecord::Base.send :extend, ActiveGit::ActiveRecord::ClassMethods

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_git-0.0.10 lib/active_git.rb
active_git-0.0.9 lib/active_git.rb
active_git-0.0.8 lib/active_git.rb