Class: Kan::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/kan/application.rb

Defined Under Namespace

Classes: InvalidScopeError

Instance Method Summary collapse

Constructor Details

#initialize(scopes = {}) ⇒ Application

Returns a new instance of Application.

Raises:



5
6
7
8
9
10
11
# File 'lib/kan/application.rb', line 5

def initialize(scopes = {})
  raise(InvalidScopeError) unless scopes.is_a?(Hash)
  raise(InvalidScopeError) if scopes.empty?

  @scopes = Hash(scopes)
  @abilities_lists = {}
end

Instance Method Details

#[](ability) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/kan/application.rb', line 13

def [](ability)
  scope, ability_name = ability.split('.')
  abilities = Array(@scopes[scope.to_sym])

  raise_scope_error(scope) if abilities.empty?
  return @abilities_lists[ability] if @abilities_lists[ability]

  @abilities_lists[ability] = AbilitiesList.new(ability_name, abilities)
end