Sha256: a06e4f2e2ebb8e7cf5c3f03426ad505e14369174a8807381c84f25611c2e8d18

Contents?: true

Size: 893 Bytes

Versions: 11

Compression:

Stored size: 893 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_server_start(&blk)
      register(:after_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.8.0.rc1 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.7.1 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.7.0 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.6.1 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.6.0 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.5.5 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.5.4 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.5.3 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.5.2 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.5.1 lib/cypress-rails/initializer_hooks.rb
cypress-rails-0.5.0 lib/cypress-rails/initializer_hooks.rb