acl_plugin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +3 -0
  2. data/README +3 -0
  3. data/Rakefile +46 -0
  4. data/lib/acl.rb +167 -0
  5. metadata +59 -0
data/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ == AclPlugin
2
+
3
+ Put appropriate LICENSE for your project here.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ == AclPlugin
2
+
3
+ You should document your project here.
@@ -0,0 +1,46 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+
6
+ require 'rubygems'
7
+ require 'rake'
8
+ require 'rake/clean'
9
+ require 'rake/gempackagetask'
10
+ require 'rake/rdoctask'
11
+ require 'rake/testtask'
12
+
13
+ spec = Gem::Specification.new do |s|
14
+ s.name = 'acl_plugin'
15
+ s.version = '0.0.1'
16
+ s.has_rdoc = true
17
+ s.extra_rdoc_files = ['README', 'LICENSE']
18
+ s.summary = 'Your summary here'
19
+ s.description = s.summary
20
+ s.author = 'Stefan Riedel'
21
+ s.email = 'sr@riedel-st.de'
22
+ s.homepage = 'http://www.riedel-st.de'
23
+ # s.executables = ['your_executable_here']
24
+ s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
25
+ s.require_path = "lib"
26
+ s.bindir = "bin"
27
+ end
28
+
29
+ Rake::GemPackageTask.new(spec) do |p|
30
+ p.gem_spec = spec
31
+ p.need_tar = true
32
+ p.need_zip = true
33
+ end
34
+
35
+ Rake::RDocTask.new do |rdoc|
36
+ files =['README', 'LICENSE', 'lib/**/*.rb']
37
+ rdoc.rdoc_files.add(files)
38
+ rdoc.main = "README" # page to start on
39
+ rdoc.title = "AclPlugin Docs"
40
+ rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
41
+ rdoc.options << '--line-numbers'
42
+ end
43
+
44
+ Rake::TestTask.new do |t|
45
+ t.test_files = FileList['test/**/*.rb']
46
+ end
@@ -0,0 +1,167 @@
1
+ module Acl
2
+ module Resource
3
+ class Registry
4
+ attr :resources
5
+ def initialize
6
+ @resources = {}
7
+ end
8
+ def get_parent(resource)
9
+ unless self.has?(resource)
10
+ raise ArgumentError, "#{resource} existiert leider nicht"
11
+ end
12
+ @resources[@resources[resource][:parent]][:instance]
13
+ end
14
+ def add(resource, parent=nil)
15
+ if self.has?(resource)
16
+ raise ArgumentError, "#{resource} existiert leider schon"
17
+ end
18
+ unless parent.nil?
19
+ @resources[parent.to_sym][:children].merge!(resource.to_sym => resource)
20
+ parent = self.get(parent)
21
+ end
22
+ @resources.merge!({resource.to_sym => {
23
+ :instance => resource,
24
+ :parent => parent,
25
+ :children => {}
26
+ }})
27
+ end
28
+ def get(resource)
29
+ unless self.has?(resource)
30
+ raise ArgumentError, "#{resource} existiert leider nicht"
31
+ end
32
+ @resources[resource.to_sym][:instance]
33
+ end
34
+ def has?(resource)
35
+ @resources.has_key? resource.to_sym
36
+ end
37
+ def inherits?(resource, inherit, only_parent=false)
38
+ unless @resources[resource][:parent].nil?
39
+ parent = self.get_parent(resource)
40
+ if parent == inherit
41
+ return true
42
+ elsif only_parent
43
+ return false
44
+ end
45
+ while !@resources[parent][:parent].nil?
46
+ parent = self.get_parent(parent)
47
+ if parent == inherit
48
+ return true
49
+ end
50
+ end
51
+ end
52
+ return false
53
+ end
54
+ def remove(resource)
55
+ unless @resources[resource.to_sym][:parent].nil?
56
+ @resources[@resources[resource.to_sym][:parent].to_sym][:children].delete(resource.to_sym)
57
+ end
58
+ if @resources[resource.to_sym][:children].respond_to?('each_key')
59
+ @resources[resource.to_sym][:children].each_key do |children_id|
60
+ self.remove(children_id)
61
+ end
62
+ end
63
+ @resources.delete(resource.to_sym)
64
+ end
65
+ def remove_all()
66
+ @resources = {}
67
+ end
68
+ def move(old_parent, new_parent)
69
+
70
+ end
71
+ end
72
+ end
73
+ module Role
74
+ class Registry
75
+ attr :roles
76
+ #initializer
77
+ def initialize
78
+ @roles = {}
79
+ end
80
+ #will add a role to the hash
81
+ #role is an object of Acl::RoleObject
82
+ #parents will allow an array or a symbol
83
+ def add(role, parents=nil)
84
+ if self.has?(role)
85
+ raise(ArgumentError, "Die rolle existiert leider schon!")
86
+ end
87
+ role_parents = {}
88
+ if parents != nil
89
+ unless parents.respond_to?(:each)
90
+ parent_id = parents.to_sym
91
+ parents = [parent_id]
92
+ end
93
+ parents.each do |parent|
94
+ current_parent_id = parent.to_sym
95
+ current_parent_object = self.get current_parent_id
96
+ role_parents.merge!({current_parent_id => current_parent_object})
97
+ @roles[current_parent_id][:children].merge!({role.to_sym => role})
98
+ end
99
+ end
100
+ @roles.merge!({role.to_sym => {
101
+ :instance => role,
102
+ :parents => role_parents,
103
+ :children => {}
104
+ }})
105
+ end
106
+ #return the role
107
+ def get(role)
108
+ unless self.has?(role)
109
+ raise(ArgumentError, "#{role.to_sym} existiert leider nicht!")
110
+ end
111
+ @roles[role.to_sym][:instance]
112
+ end
113
+ #return true if role is in @roles hash
114
+ def has?(role)
115
+ @roles.has_key? role.to_sym
116
+ end
117
+ def get_parents(role)
118
+ @roles[role.to_sym][:parents]
119
+ end
120
+ #return true if role is in inherits? and if
121
+ #only_parents are true we will show only in parents hash
122
+ #of the role
123
+ def inherits?(role, inherit, only_parents=false)
124
+ begin
125
+ role_object = self.get(role)
126
+ #hier müssen wir ordentliches ausnahme handling einbaun
127
+ rescue
128
+ return false
129
+ end
130
+ role_id = role_object.to_sym
131
+ inherit_id = self.get(inherit).to_sym
132
+ inherits = (@roles[role_id][:parents][inherit_id].nil? == true) ? false : true
133
+ if inherits || only_parents
134
+ return inherits
135
+ end
136
+ @roles[role_id][:parents].each_key do |parent_id|
137
+ if self.inherits?(parent_id, inherit_id)
138
+ return true
139
+ end
140
+ end
141
+ return false
142
+ end
143
+ #removes the role and will return true or false
144
+ def remove(role)
145
+ role_id = self.get(role).to_sym
146
+ if @roles[role_id][:children].respond_to?('each_key')
147
+ @roles[role_id][:children].each_key do |children_id|
148
+ @roles[children_id][:parents].delete(role_id)
149
+ end
150
+ end
151
+ if @roles[role_id][:parents].respond_to?('each_key')
152
+ @roles[role_id][:parents].each_key do |parent_id|
153
+ @roles[parent_id][:children].delete(role_id)
154
+ end
155
+ end
156
+ @roles.delete(role_id) != nil
157
+ end
158
+ #will niling the @roles hash
159
+ def remove_all
160
+ @roles = {}
161
+ end
162
+ def move(old_parent, new_parent)
163
+
164
+ end
165
+ end
166
+ end
167
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acl_plugin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stefan Riedel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-26 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Your summary here
17
+ email: sr@riedel-st.de
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - LICENSE
25
+ files:
26
+ - LICENSE
27
+ - README
28
+ - Rakefile
29
+ - lib/acl.rb
30
+ has_rdoc: true
31
+ homepage: http://www.riedel-st.de
32
+ licenses: []
33
+
34
+ post_install_message:
35
+ rdoc_options: []
36
+
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ requirements: []
52
+
53
+ rubyforge_project:
54
+ rubygems_version: 1.3.4
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: Your summary here
58
+ test_files: []
59
+