Class: CrazyDoll::Event
- Inherits:
-
Object
- Object
- CrazyDoll::Event
- Defined in:
- lib/crazy_doll/events.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#real_method_name ⇒ Object
readonly
Returns the value of attribute real_method_name.
Instance Method Summary collapse
- #call(opts, line = '') ⇒ Object
-
#initialize(klass, opts = {}) ⇒ Event
constructor
A new instance of Event.
- #verify(opts) ⇒ Object
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
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
3 4 5 |
# File 'lib/crazy_doll/events.rb', line 3 def klass @klass end |
#method_name ⇒ Object (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_name ⇒ Object (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
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 |