Class: CrazyDoll::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/crazy_doll/events.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, opts = {}) ⇒ Event

Returns a new instance of Event.



4
5
6
7
8
# File 'lib/crazy_doll/events.rb', line 4

def initialize(klass, opts = {})
  @klass = klass
  verify(opts)
  @real_method_name, @method_name = opts[:real_method_name], opts[:method_name]
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'lib/crazy_doll/events.rb', line 3

def klass
  @klass
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



3
4
5
# File 'lib/crazy_doll/events.rb', line 3

def method_name
  @method_name
end

#real_method_nameObject (readonly)

Returns the value of attribute real_method_name.



3
4
5
# File 'lib/crazy_doll/events.rb', line 3

def real_method_name
  @real_method_name
end

Instance Method Details

#call(opts, line = '') ⇒ Object



18
19
20
21
22
# File 'lib/crazy_doll/events.rb', line 18

def call(opts, line='')
  @klass.opts = opts
  @klass.line = line
  @klass.send(@real_method_name) rescue nil
end

#verify(opts) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
# File 'lib/crazy_doll/events.rb', line 10

def verify(opts)
  errors = []
  errors << 'need a real method name' unless @klass.respond_to?(opts[:real_method_name])
  errors << 'need a method name' unless opts[:method_name]
  return true if errors.empty?
  raise ArgumentError, errors.join(', ')
end