Class: CanTango::Ability::Executor::Modal

Inherits:
Base
  • Object
show all
Extended by:
ClassMethods
Defined in:
lib/cantango/ability/executor/modal.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary

Attributes inherited from Base

#ability, #executed, #modes, #options

Attributes included from Helpers::Debug

#debug_writer, #do_debug

Attributes inherited from Base

#candidate, #options

Instance Method Summary collapse

Methods included from ClassMethods

build

Methods inherited from Base

#executed?

Methods included from Builder

included

Methods included from Callbacks

#handle_callbacks, included, #within_callbacks

Methods included from Helpers::Debug

#debug, #debug?, included

Methods included from CanTango::Ability::Executor

included

Methods included from Rules

#clear_rules!, #default_rules, #normalize_rules!, #rules

Methods inherited from Base

#session

Constructor Details

#initialize(ability, modes, options = {}) ⇒ Modal

Returns a new instance of Modal.



3
4
5
6
7
# File 'lib/cantango/ability/executor/modal.rb', line 3

def initialize ability, modes, options = {}
  super ability, options
  extract_modes modes
  execute
end

Instance Method Details

#calculate_rulesObject



16
17
18
19
20
21
22
# File 'lib/cantango/ability/executor/modal.rb', line 16

def calculate_rules
  @rules = modes.inject([]) do |result, mode|
    result = result + modal_rules(mode)
    result
  end
  normalize_rules!
end

#executeObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/cantango/ability/executor/modal.rb', line 24

def execute
  return if executed?
  clear_rules!
  calculate_rules
rescue Exception => e
  debug e.message      
ensure
  @executed = true
  rules
end

#finderObject



35
36
37
# File 'lib/cantango/ability/executor/modal.rb', line 35

def finder
  @finder ||= CanTango::Ability::Mode::Finder.new self
end