Module: Fib::Additions::TargeterAddition

Extended by:
ActiveSupport::Concern
Includes:
ContainerAddition
Defined in:
lib/fib/additions/targeter_addition.rb

Instance Method Summary collapse

Methods included from ContainerAddition

#fib_container, #fib_inherit

Instance Method Details

#add_permissions(*permission_keys) ⇒ Object



33
34
35
36
37
# File 'lib/fib/additions/targeter_addition.rb', line 33

def add_permissions *permission_keys
  new_permissions = fib_container.permissions.extract_by_keys permission_keys
  @permissions += new_permissions
  save_permissions
end

#clear_permissionsObject



45
46
47
48
# File 'lib/fib/additions/targeter_addition.rb', line 45

def clear_permissions
  fib_container.fpa.clear fib_redis_key
  @permissions = nil
end

#create_permissions(*permission_keys) ⇒ Object



22
23
24
25
26
# File 'lib/fib/additions/targeter_addition.rb', line 22

def create_permissions *permission_keys
  clear_permissions
  new_permissions permission_keys
  save_permissions
end

#del_permissions(*permission_keys) ⇒ Object



39
40
41
42
43
# File 'lib/fib/additions/targeter_addition.rb', line 39

def del_permissions *permission_keys
  del_permissions = fib_container.permissions.extract_by_keys permission_keys
  @permissions -= del_permissions
  save_permissions
end

#fib_identifyObject



58
59
60
61
# File 'lib/fib/additions/targeter_addition.rb', line 58

def fib_identify
  raise UnSetTargeterIdentify, "Please rewrite [fib_identify] method and set only sign in #{self.class.name}" unless respond_to? :id
  id
end

#fib_redis_keyObject



54
55
56
# File 'lib/fib/additions/targeter_addition.rb', line 54

def fib_redis_key
  "Fib:#{fib_container.key}:#{self.class.name}:#{fib_identify}"
end

#get_persistence_permissionsObject



50
51
52
# File 'lib/fib/additions/targeter_addition.rb', line 50

def get_persistence_permissions
  fib_container.restore_permissions(fib_redis_key)
end

#new_permissions(*permission_keys) ⇒ Object



28
29
30
31
# File 'lib/fib/additions/targeter_addition.rb', line 28

def new_permissions *permission_keys
  permission_keys = [permission_keys].flatten
  @permissions = fib_container.permissions.extract_by_keys permission_keys
end

#permissionsObject

最终权限来源自于权限范围与持久化权限的并集



10
11
12
# File 'lib/fib/additions/targeter_addition.rb', line 10

def permissions
  @permissions ||= permissions_scope & (get_persistence_permissions || Fib::PermissionsCollection.new)
end

#permissions_scopeObject



14
15
16
# File 'lib/fib/additions/targeter_addition.rb', line 14

def permissions_scope
  fib_inherit.permissions
end

#save_permissionsObject



18
19
20
# File 'lib/fib/additions/targeter_addition.rb', line 18

def save_permissions
  fib_container.fpa.save fib_redis_key, permissions.keys
end