Class: CanTango::PermissionEngine::Loader::Categories

Inherits:
Base
  • Object
show all
Defined in:
lib/cantango/permission_engine/loader/categories.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited, #yml_content

Constructor Details

#initialize(file = nil) ⇒ Categories

Returns a new instance of Categories.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cantango/permission_engine/loader/categories.rb', line 7

def initialize file = nil
  begin
    @file_name = file || categories_config_file
    yml_content.each do |key, value|
      parser.parse(categories, key, value)
    end

  rescue RuntimeError => e
    raise "CanTango::Categories::Loader Error: The categories for the file #{file_name} could not be loaded - cause was #{e}"
  end
end

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories.



5
6
7
# File 'lib/cantango/permission_engine/loader/categories.rb', line 5

def categories
  @categories
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



5
6
7
# File 'lib/cantango/permission_engine/loader/categories.rb', line 5

def file_name
  @file_name
end

Instance Method Details

#categories_config_fileObject



36
37
38
# File 'lib/cantango/permission_engine/loader/categories.rb', line 36

def categories_config_file
  get_config_file 'categories'
end

#category(name) ⇒ Object



19
20
21
# File 'lib/cantango/permission_engine/loader/categories.rb', line 19

def category name
  categories.category(name).subjects
end

#config_pathObject



44
45
46
# File 'lib/cantango/permission_engine/loader/categories.rb', line 44

def config_path
  CanTango.config.permission_engine.config_path
end

#get_config_file(name) ⇒ Object



40
41
42
# File 'lib/cantango/permission_engine/loader/categories.rb', line 40

def get_config_file name
  File.join(config_path, "#{name}.yml")
end

#load_categories(name = nil) ⇒ Object



31
32
33
34
# File 'lib/cantango/permission_engine/loader/categories.rb', line 31

def load_categories name = nil
  name ||= categories_config_file
  CanTango::Categories::Loader.new name
end

#parserObject



27
28
29
# File 'lib/cantango/permission_engine/loader/categories.rb', line 27

def parser
  @parser ||= CanTango::PermissionEngine::Parser::Categories.new
end