Class: CanTango::Loader::Categories
- Inherits:
-
Yaml
- Object
- Yaml
- CanTango::Loader::Categories
- Defined in:
- lib/cantango/permits_ext/loader/categories.rb
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
Instance Method Summary collapse
- #categories_config_file ⇒ Object
- #category(name) ⇒ Object
- #config_path ⇒ Object
- #get_config_file(name) ⇒ Object
-
#initialize(file = nil) ⇒ Categories
constructor
A new instance of Categories.
- #load_categories(name = nil) ⇒ Object
- #parser ⇒ Object
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
#categories ⇒ Object (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_name ⇒ Object (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_file ⇒ Object
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_path ⇒ Object
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 |
#parser ⇒ Object
28 29 30 |
# File 'lib/cantango/permits_ext/loader/categories.rb', line 28 def parser @parser ||= CanTango::Parser::Categories.new end |