Class: Sanction::Permission

Inherits:
Object
  • Object
show all
Defined in:
lib/sanction/permission.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(permission_graph, *predicates) ⇒ Permission

Returns a new instance of Permission.



6
7
8
9
# File 'lib/sanction/permission.rb', line 6

def initialize(permission_graph, *predicates)
  @graph      = permission_graph
  @predicates = predicates
end

Instance Attribute Details

#predicatesObject (readonly)

Returns the value of attribute predicates.



4
5
6
# File 'lib/sanction/permission.rb', line 4

def predicates
  @predicates
end

Instance Method Details

#pathObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sanction/permission.rb', line 11

def path
  @path ||= begin
    path = @graph.root
    @predicates.each do |predicate|
      if predicate.is_a?(Class)
        path = path[predicate.to_s.demodulize.underscore.to_sym]
      else
        path = path[predicate.class.to_s.demodulize.underscore.to_sym][predicate.id]
      end
    end
    path
  end
end

#permitted?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/sanction/permission.rb', line 29

def permitted?
  path.permitted?
end

#permitted_with_scope?(scope) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/sanction/permission.rb', line 33

def permitted_with_scope?(scope)
  permitted? && path.has_scope?(scope)
end

#persisted?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/sanction/permission.rb', line 25

def persisted?
  path.persisted?
end