Class: CanTango::PermissionEngine::Parser::Category
- Defined in:
- lib/cantango/permission_engine/parser/category.rb
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
remove the ‘@’ prefix to get the category name look up the category and get models referenced by said category.
Attributes inherited from Rule
#action, #method, #model, #target
Instance Method Summary collapse
- #category_models_for(name) ⇒ Object
-
#initialize(method, action, target) ⇒ Category
constructor
A new instance of Category.
- #load_categories ⇒ Object
- #parse ⇒ Object
Methods inherited from Rule
Constructor Details
#initialize(method, action, target) ⇒ Category
Returns a new instance of Category.
9 10 11 12 |
# File 'lib/cantango/permission_engine/parser/category.rb', line 9 def initialize method, action, target super load_categories end |
Instance Attribute Details
#categories ⇒ Object (readonly)
remove the ‘@’ prefix to get the category name look up the category and get models referenced by said category
7 8 9 |
# File 'lib/cantango/permission_engine/parser/category.rb', line 7 def categories @categories end |
Instance Method Details
#category_models_for(name) ⇒ Object
22 23 24 |
# File 'lib/cantango/permission_engine/parser/category.rb', line 22 def category_models_for name categories.registered[name.to_s] end |
#load_categories ⇒ Object
26 27 28 |
# File 'lib/cantango/permission_engine/parser/category.rb', line 26 def load_categories @categories = CanTango::PermissionEngine::Loader::Categories.new.categories end |
#parse ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/cantango/permission_engine/parser/category.rb', line 14 def parse cat_name = target.gsub(/^\^/, '').to_sym targets = category_models_for(cat_name).map{|model| parse_class(model)} targets.inject([]) do |statements, target| statements << "#{method}(:#{action}, #{target})" end end |