Class: Fib::Permission

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/fib/permission.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, options = {}) ⇒ Permission

Returns a new instance of Permission.



11
12
13
14
15
16
17
# File 'lib/fib/permission.rb', line 11

def initialize key, options={}
  @key = key.to_sym
  @name = options[:name] || key.to_s
  @package = options[:package] || Fib::ElementPackage.new
  @bind = options[:bind] || []
  @display = options.key?(:display) ? options[:display] : true
end

Instance Attribute Details

#bindObject (readonly)

Returns the value of attribute bind.



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

def bind
  @bind
end

#containerObject

Returns the value of attribute container.



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

def container
  @container
end

#displayObject (readonly)

Returns the value of attribute display.



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

def display
  @display
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#packageObject (readonly)

Returns the value of attribute package.



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

def package
  @package
end

Instance Method Details

#bind_packagesObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fib/permission.rb', line 19

def bind_packages
  return [] unless bind.present? || container.present?

  packages = []
  bind.each do |b|
    p = container.permissions.permissions[b]
    next unless p.present?
    packages << p.package
    packages << p.bind_packages
  end
  packages.flatten
end

#bind_permission(*permission_keys) ⇒ Object



52
53
54
55
# File 'lib/fib/permission.rb', line 52

def bind_permission *permission_keys
  @bind << permission_keys.flatten.map(&:to_sym)
  @bind.flatten!.uniq!
end

#def_action(controller, action, &block) ⇒ Object



32
33
34
# File 'lib/fib/permission.rb', line 32

def def_action controller, action, &block
  @package << Fib::Element.create_action(controller, action, &block)
end

#def_key(key, &block) ⇒ Object



40
41
42
# File 'lib/fib/permission.rb', line 40

def def_key key, &block
  @package << Fib::Element.create_key(key, &block)
end

#def_url(url, &block) ⇒ Object



36
37
38
# File 'lib/fib/permission.rb', line 36

def def_url url, &block
  @package << Fib::Element.create_url(url, &block)
end

#display_offObject



48
49
50
# File 'lib/fib/permission.rb', line 48

def display_off
  @display = false
end

#display_onObject



44
45
46
# File 'lib/fib/permission.rb', line 44

def display_on
  @display = true
end

#inject_elements_permissionObject



57
58
59
60
61
# File 'lib/fib/permission.rb', line 57

def inject_elements_permission
  package.origin_elements.values.flatten.each do |e|
    e.set_permission self
  end
end