123456789_123456789_123456789_123456789_123456789_

Class: Test::Unit::Fixture::HookPoint

Relationships & Source Files
Inherits: Object
Defined in: lib/test/unit/fixture.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(default_options) ⇒ HookPoint

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 92

def initialize(default_options)
  @default_options = default_options
  @before_prepend_callbacks = []
  @before_append_callbacks = []
  @after_prepend_callbacks = []
  @after_append_callbacks = []
  @unregistered_callbacks = []
end

Instance Method Details

#add_callback(method_name_or_callback, before_how, after_how) (private)

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 148

def add_callback(method_name_or_callback, before_how, after_how)
  case before_how
  when :prepend
    @before_prepend_callbacks =
      [method_name_or_callback] | @before_prepend_callbacks
  when :append
    @before_append_callbacks |= [method_name_or_callback]
  else
    case after_how
    when :prepend
      @after_prepend_callbacks =
        [method_name_or_callback] | @after_prepend_callbacks
    when :append
      @after_append_callbacks |= [method_name_or_callback]
    end
  end
end

#after_append_callbacks

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 134

def after_append_callbacks
  @after_append_callbacks - @unregistered_callbacks
end

#after_prepend_callbacks

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 130

def after_prepend_callbacks
  @after_prepend_callbacks - @unregistered_callbacks
end

#before_append_callbacks

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 126

def before_append_callbacks
  @before_append_callbacks - @unregistered_callbacks
end

#before_prepend_callbacks

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 122

def before_prepend_callbacks
  @before_prepend_callbacks - @unregistered_callbacks
end

#register(method_name_or_callback, options = nil)

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 101

def register(method_name_or_callback, options=nil)
  options ||= {}
  unless valid_register_options?(options)
    message = "must be {:before => :prepend}, " +
      "{:before => :append}, {:after => :prepend} or " +
      "{:after => :append}: #{options.inspect}"
    raise ArgumentError, message
  end

  if options.empty?
    options = @default_options
  end
  before_how = options[:before]
  after_how = options[:after]
  add_callback(method_name_or_callback, before_how, after_how)
end

#unregister(method_name_or_callback)

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 118

def unregister(method_name_or_callback)
  @unregistered_callbacks << method_name_or_callback
end

#valid_register_options?(options) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/test/unit/fixture.rb', line 139

def valid_register_options?(options)
  return true if options.empty?
  return false if options.size > 1

  key = options.keys.first
  [:before, :after].include?(key) and
    [:prepend, :append].include?(options[key])
end