Class: CanTango::Loader::Categories

Inherits:
Yaml
  • Object
show all
Defined in:
lib/cantango/permits_ext/loader/categories.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ Categories

Returns a new instance of Categories.



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

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.



4
5
6
# File 'lib/cantango/permits_ext/loader/categories.rb', line 4

def categories
  @categories
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



4
5
6
# File 'lib/cantango/permits_ext/loader/categories.rb', line 4

def file_name
  @file_name
end

Instance Method Details

#categories_config_fileObject



37
38
39
# File 'lib/cantango/permits_ext/loader/categories.rb', line 37

def categories_config_file
  get_config_file 'categories'
end

#category(name) ⇒ Object



18
19
20
21
22
# File 'lib/cantango/permits_ext/loader/categories.rb', line 18

def category name
  categories.category(name).subjects
rescue
  []
end

#config_pathObject



45
46
47
# File 'lib/cantango/permits_ext/loader/categories.rb', line 45

def config_path
  CanTango.config.engine(:permit).config_path
end

#get_config_file(name) ⇒ Object



41
42
43
# File 'lib/cantango/permits_ext/loader/categories.rb', line 41

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

#load_categories(name = nil) ⇒ Object



32
33
34
35
# File 'lib/cantango/permits_ext/loader/categories.rb', line 32

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

#parserObject



28
29
30
# File 'lib/cantango/permits_ext/loader/categories.rb', line 28

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