Class: CanTango::PermissionEngine::Permission

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Permission

Returns a new instance of Permission.



7
8
9
10
11
# File 'lib/cantango/permission_engine/permission.rb', line 7

def initialize name
  @name = name
  @static_rules = Hashie::Mash.new
  @compiled_rules = Hashie::Mash.new
end

Instance Attribute Details

#compiled_rulesObject

rules is a Hashie, a Hash where keys can also be accessed as method calls



5
6
7
# File 'lib/cantango/permission_engine/permission.rb', line 5

def compiled_rules
  @compiled_rules
end

#nameObject

rules is a Hashie, a Hash where keys can also be accessed as method calls



5
6
7
# File 'lib/cantango/permission_engine/permission.rb', line 5

def name
  @name
end

#static_rulesObject

rules is a Hashie, a Hash where keys can also be accessed as method calls



5
6
7
# File 'lib/cantango/permission_engine/permission.rb', line 5

def static_rules
  @static_rules
end

Instance Method Details

#compile_rules!Object



30
31
32
33
# File 'lib/cantango/permission_engine/permission.rb', line 30

def compile_rules!
  compiler.compile! self
  @compiled_rules = compiler.to_hashie
end

#compilerObject



35
36
37
# File 'lib/cantango/permission_engine/permission.rb', line 35

def compiler
  @compiler ||= CanTango::PermissionEngine::Compiler.new
end

#keyObject



13
14
15
# File 'lib/cantango/permission_engine/permission.rb', line 13

def key
  name.to_s
end

#to_compiled_hashObject



21
22
23
# File 'lib/cantango/permission_engine/permission.rb', line 21

def to_compiled_hash
  {key => compiled_rules}
end

#to_hashObject



17
18
19
# File 'lib/cantango/permission_engine/permission.rb', line 17

def to_hash
  {key => static_rules.to_hash}
end