Class: CanTango::PermissionEngine::Parser::Category

Inherits:
Rule
  • Object
show all
Defined in:
lib/cantango/permission_engine/parser/category.rb

Instance Attribute Summary collapse

Attributes inherited from Rule

#action, #method, #model, #target

Instance Method Summary collapse

Methods inherited from Rule

#parse_class, #try_class

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

#categoriesObject (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_categoriesObject



26
27
28
# File 'lib/cantango/permission_engine/parser/category.rb', line 26

def load_categories
  @categories = CanTango::PermissionEngine::Loader::Categories.new.categories
end

#parseObject



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