Sha256: edebd7744fa499df4954b9da0b3cf78bc1789a2fbeb0200bd8da0660f31897c2

Contents?: true

Size: 840 Bytes

Versions: 3

Compression:

Stored size: 840 Bytes

Contents

module CanTango
  class AbilityExecutor < CanTango::Ability
    attr_reader :rules

    def initialize candidate, options = {}
      raise "Candidate must be something!" if !candidate
      @candidate, @options = [candidate, options]
      @rules = cached_rules + non_cached_rules
    end

    def cached_rules
      cache_mode? ? cached_ability.send(:rules) : []
    end

    def non_cached_rules
      no_cache_mode? ? non_cached_ability.send(:rules) : []
    end

    def cached_ability
      CanTango::CachedAbility.new candidate, options
    end

    def non_cached_ability
      CanTango::Ability.new candidate, options
    end

    protected

    def no_cache_mode?
      modes.include?(:no_cache)
    end

    def cache_mode?
      modes.include?(:cache)
    end

    def modes
      CanTango.config.ability.modes
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cantango-0.9.4.1 lib/cantango/ability_executor.rb
cantango-0.9.4 lib/cantango/ability_executor.rb
cantango-0.9.3.2 lib/cantango/ability_executor.rb