Sha256: 6a1b439d5c73b85ae626c0a12a8242bdbec203b48e1a8ee83640c2848aa3a8f9

Contents?: true

Size: 810 Bytes

Versions: 11

Compression:

Stored size: 810 Bytes

Contents

module CypressRails
  def self.hooks
    InitializerHooks.instance
  end

  class InitializerHooks
    def self.instance
      @instance ||= new
    end

    def before_server_start(&blk)
      register(:before_server_start, blk)
    end

    def after_transaction_start(&blk)
      register(:after_transaction_start, blk)
    end

    def after_state_reset(&blk)
      register(:after_state_reset, blk)
    end

    def before_server_stop(&blk)
      register(:before_server_stop, blk)
    end

    def reset!
      @hooks = {}
    end

    def run(name)
      return unless @hooks[name]
      @hooks[name].each do |blk|
        blk.call
      end
    end

    private

    def register(name, blk)
      @hooks[name] ||= []
      @hooks[name] << blk
    end

    def initialize
      reset!
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cypress-rails-0.4.2 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.4.1 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.4.0 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.3.0 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.2.0 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.1.5 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.1.4 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.1.3 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.1.2 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.1.1 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.1.0 lib/cypress-rails/initializer_hooks.rb