Sha256: 81ecba4fadeb20ac7efba1c59c4f14dd8cd4984a163a88724d1adfcf4ad4eb0c

Contents?: true

Size: 972 Bytes

Versions: 2

Compression:

Stored size: 972 Bytes

Contents

module CanTango::Ability::Executor
  class Modal < Base    
    def initialize candidate, modes, options = {}
      super candidate, options
      modes = [modes].flatten if modes
      raise ArgumentError, "Modes must be a list of modes to execute!" if modes.blank?
      @modes = modes
    end

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

    def execute
      clear_rules!
      calculate_rules
      return rules
    rescue Exception => e
      debug e.message
      rules
    end

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

    protected

    def modal_rules mode
      puts "modal rules: #{mode}"
      mode?(mode) ? executor(mode).execute : []
    end

    def executor mode
      @executor ||= finder.executor_for(mode)
    end

    def mode? mode
      modes.include?(mode)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cantango-core-0.1.5 lib/cantango/ability/executor/modal.rb
cantango-core-0.1.4 lib/cantango/ability/executor/modal.rb