Class: CanTango::PermissionEngine::Parser::Relationship

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

Instance Attribute Summary

Attributes inherited from Rule

#action, #method, #model, #target

Instance Method Summary collapse

Methods inherited from Rule

#initialize, #parse_class, #try_class

Constructor Details

This class inherits a constructor from CanTango::PermissionEngine::Parser::Rule

Instance Method Details

#parseObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cantango/permission_engine/parser/relationship.rb', line 5

def parse
  match = target[/(\w+)#(\w+)=(.+)/]
  @target = match[$1]
  lstat = match[$2]
  rstat = match[$3]

  model_class = try_class
  raise "#{model_class} has no ##{lstat}!" if !model_class.new.respond_to?(lstat.to_sym)
  conditions = ":#{lstat} => #{rstat}"

  target_and_conditions = [ target, conditions ].compact.join(', ')
  "#{method}(:#{action}, #{target_and_conditions})"
end