Class: Cases::Case

Inherits:
Object
  • Object
show all
Defined in:
lib/cases/case.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, event, options = {}, &action_block) ⇒ Case

Returns a new instance of Case.



10
11
12
13
14
15
16
17
# File 'lib/cases/case.rb', line 10

def initialize(method, event, options = {}, &action_block)
  @method = method
  @event = event
  @options = options
  @action_block = action_block

  register
end

Instance Attribute Details

#action_blockObject (readonly)

Returns the value of attribute action_block.



4
5
6
# File 'lib/cases/case.rb', line 4

def action_block
  @action_block
end

#eventObject (readonly)

Returns the value of attribute event.



4
5
6
# File 'lib/cases/case.rb', line 4

def event
  @event
end

#methodObject (readonly)

Returns the value of attribute method.



4
5
6
# File 'lib/cases/case.rb', line 4

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/cases/case.rb', line 4

def options
  @options
end

#resultObject

Returns the value of attribute result.



3
4
5
# File 'lib/cases/case.rb', line 3

def result
  @result
end

Class Method Details

.allObject



6
7
8
# File 'lib/cases/case.rb', line 6

def self.all
  @_all ||= {}
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
22
# File 'lib/cases/case.rb', line 19

def ==(other)
  method == other.method &&
    event == other.event
end

#execute(object, result) ⇒ Object



24
25
26
27
28
# File 'lib/cases/case.rb', line 24

def execute(object, result)
  return if !result.send(event)

  self.result = action_block.call(options[:on_self] ? object : result)
end