cantango-core 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/Gemfile +7 -1
  2. data/Gemfile.lock +70 -12
  3. data/README.mdown +16 -14
  4. data/VERSION +1 -1
  5. data/cantango-core.gemspec +41 -51
  6. data/lib/cantango/ability/base/callbacks.rb +37 -0
  7. data/lib/cantango/ability/base.rb +21 -8
  8. data/lib/cantango/ability/cache.rb +1 -1
  9. data/lib/cantango/ability/executor/modes.rb +6 -6
  10. data/lib/cantango/ability/executor/no_cache_mode.rb +2 -6
  11. data/lib/cantango/ability/executor.rb +1 -1
  12. data/lib/cantango/ability/helper/account.rb +6 -10
  13. data/lib/cantango/ability/helper/engine.rb +22 -26
  14. data/lib/cantango/ability/helper/user.rb +10 -14
  15. data/lib/cantango/ability/helper.rb +1 -1
  16. data/lib/cantango/ability.rb +7 -2
  17. data/lib/cantango/adaptor/active_record.rb +6 -0
  18. data/lib/cantango/adaptor/data_mapper.rb +5 -0
  19. data/lib/cantango/adaptor/generic.rb +12 -0
  20. data/lib/cantango/adaptor/mongo.rb +13 -0
  21. data/lib/cantango/adaptor/mongo_mapper.rb +5 -0
  22. data/lib/cantango/adaptor/mongoid.rb +5 -0
  23. data/lib/cantango/adaptor/relational.rb +8 -0
  24. data/lib/cantango/{rules/adaptor.rb → adaptor.rb} +4 -4
  25. data/lib/cantango/{rules → cancan}/rule_class.rb +1 -1
  26. data/lib/cantango/cancan.rb +5 -0
  27. data/lib/cantango/core.rb +5 -13
  28. data/lib/cantango/engine.rb +6 -16
  29. data/lib/cantango/filter/base.rb +1 -1
  30. data/lib/cantango/helpers/debug.rb +31 -1
  31. data/lib/cantango/loader/yaml.rb +2 -11
  32. data/lib/cantango/model/guest.rb +3 -1
  33. data/spec/cantango/ability/base_spec.rb +13 -63
  34. data/spec/cantango/ability/cache/simple_key_spec.rb +29 -0
  35. data/spec/cantango/ability/executor/base_spec.rb +12 -52
  36. data/spec/cantango/ability/executor/custom_spec.rb +51 -0
  37. data/spec/cantango/ability/executor/modes_spec.rb +27 -49
  38. data/spec/cantango/ability/executor/no_cache_mode_spec.rb +29 -0
  39. data/spec/cantango/ability/helper/account_spec.rb +37 -0
  40. data/spec/cantango/ability/helper/engine_spec.rb +36 -0
  41. data/spec/cantango/ability/helper/user_spec.rb +38 -0
  42. data/spec/cantango/adaptor/active_record_spec.rb +38 -0
  43. data/spec/cantango/adaptor/data_mapper_spec.rb +39 -0
  44. data/spec/cantango/{rules/adaptor → adaptor}/mongo_mapper_spec.rb +0 -0
  45. data/spec/cantango/{rules/adaptor → adaptor}/mongoid_spec.rb +0 -0
  46. data/spec/cantango/cancan/rule_spec.rb +5 -0
  47. data/spec/cantango/core_spec.rb +0 -2
  48. data/spec/cantango/engine_spec.rb +51 -0
  49. data/spec/cantango/filter/base_spec.rb +25 -0
  50. data/spec/cantango/helpers/debug_spec.rb +29 -0
  51. data/spec/cantango/loader/yaml_spec.rb +5 -0
  52. data/spec/cantango/model/guest_spec.rb +14 -0
  53. data/spec/cantango/rspec/be_allowed_to_spec.rb +5 -0
  54. data/spec/cantango/scope/ability_spec.rb +33 -0
  55. data/spec/fixtures/models/account.rb +7 -0
  56. data/spec/fixtures/models/admin.rb +2 -0
  57. data/spec/fixtures/models/admin_account.rb +8 -0
  58. data/spec/fixtures/models/items.rb +11 -0
  59. data/spec/fixtures/models/user.rb +20 -0
  60. data/spec/fixtures/models.rb +2 -0
  61. data/spec/spec_helper.rb +4 -0
  62. metadata +60 -67
  63. data/lib/cantango/ability/executor/cache_mode.rb +0 -33
  64. data/lib/cantango/ability/helper/role.rb +0 -21
  65. data/lib/cantango/ability/helper/role_group.rb +0 -21
  66. data/lib/cantango/macros/account.rb +0 -14
  67. data/lib/cantango/macros/user.rb +0 -16
  68. data/lib/cantango/macros.rb +0 -11
  69. data/lib/cantango/rules/adaptor/active_record.rb +0 -10
  70. data/lib/cantango/rules/adaptor/data_mapper.rb +0 -11
  71. data/lib/cantango/rules/adaptor/generic.rb +0 -16
  72. data/lib/cantango/rules/adaptor/mongo.rb +0 -19
  73. data/lib/cantango/rules/adaptor/mongo_mapper.rb +0 -10
  74. data/lib/cantango/rules/adaptor/mongoid.rb +0 -9
  75. data/lib/cantango/rules/adaptor/relational.rb +0 -13
  76. data/lib/cantango/rules/dsl.rb +0 -24
  77. data/lib/cantango/rules/relation.rb +0 -67
  78. data/lib/cantango/rules/scope.rb +0 -24
  79. data/lib/cantango/rules.rb +0 -8
  80. data/spec/cantango/ability/cached_spec.rb +0 -0
  81. data/spec/cantango/ability/executor/base2.rb +0 -75
  82. data/spec/cantango/ability/executor/cache_mode_spec.rb +0 -77
  83. data/spec/cantango/macros/account_spec.rb +0 -0
  84. data/spec/cantango/macros/user_spec.rb +0 -0
  85. data/spec/cantango/rules/adaptor/active_record_spec.rb +0 -0
  86. data/spec/cantango/rules/adaptor/data_mapper_spec.rb +0 -0
  87. data/spec/cantango/rules/adaptor_spec.rb +0 -0
  88. data/spec/cantango/rules/dsl_spec.rb +0 -0
  89. data/spec/cantango/rules/relation_spec.rb +0 -0
  90. data/spec/cantango/rules/rule_class_spec.rb +0 -0
  91. data/spec/cantango/rules/scope_spec.rb +0 -0
  92. data/spec/cantango/rules_spec.rb +0 -55
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ group :default do
4
4
  gem 'rails', '>= 3.0.1'
5
5
  gem 'cancan', '>= 1.4'
6
6
  gem 'sugar-high', '>= 0.6.0'
7
- gem 'sweetloader', '~> 0.1.0'
7
+ gem 'sweetloader', '~> 0.1.5'
8
8
  gem 'hashie'
9
9
  end
10
10
 
@@ -15,6 +15,12 @@ group :test do
15
15
  gem 'database_cleaner'
16
16
  gem 'factory_girl'
17
17
 
18
+ # Adapters
19
+ gem 'activerecord', '>= 3'
20
+ gem 'datamapper', '>= 1.1'
21
+ gem 'mongoid', '>= 2.2'
22
+ gem 'mongo_mapper', '>= 0.9'
23
+
18
24
  # Specs
19
25
  gem 'spork'
20
26
  gem 'capybara'
data/Gemfile.lock CHANGED
@@ -33,6 +33,7 @@ GEM
33
33
  arel (2.2.1)
34
34
  babosa (0.3.5)
35
35
  bcrypt-ruby (3.0.1)
36
+ bson (1.4.0)
36
37
  builder (3.0.0)
37
38
  cancan (1.6.7)
38
39
  capybara (1.1.2)
@@ -42,7 +43,7 @@ GEM
42
43
  rack-test (>= 0.5.4)
43
44
  selenium-webdriver (~> 2.0)
44
45
  xpath (~> 0.1.4)
45
- childprocess (0.2.2)
46
+ childprocess (0.2.3)
46
47
  ffi (~> 1.0.6)
47
48
  code-spec (0.4.0)
48
49
  activesupport (>= 3.0.1)
@@ -54,15 +55,54 @@ GEM
54
55
  activesupport (>= 2.3.5)
55
56
  colorize (>= 0.5)
56
57
  database_cleaner (0.7.0)
58
+ datamapper (1.2.0)
59
+ dm-aggregates (~> 1.2.0)
60
+ dm-constraints (~> 1.2.0)
61
+ dm-core (~> 1.2.0)
62
+ dm-migrations (~> 1.2.0)
63
+ dm-serializer (~> 1.2.0)
64
+ dm-timestamps (~> 1.2.0)
65
+ dm-transactions (~> 1.2.0)
66
+ dm-types (~> 1.2.0)
67
+ dm-validations (~> 1.2.0)
57
68
  decent_exposure (1.0.1)
58
- devise (1.5.1)
69
+ devise (1.5.2)
59
70
  bcrypt-ruby (~> 3.0)
60
71
  orm_adapter (~> 0.0.3)
61
72
  warden (~> 1.1)
62
73
  diff-lcs (1.1.3)
74
+ dm-aggregates (1.2.0)
75
+ dm-core (~> 1.2.0)
76
+ dm-constraints (1.2.0)
77
+ dm-core (~> 1.2.0)
78
+ dm-core (1.2.0)
79
+ addressable (~> 2.2.6)
80
+ dm-migrations (1.2.0)
81
+ dm-core (~> 1.2.0)
82
+ dm-serializer (1.2.1)
83
+ dm-core (~> 1.2.0)
84
+ fastercsv (~> 1.5.4)
85
+ json (~> 1.6.1)
86
+ json_pure (~> 1.6.1)
87
+ multi_json (~> 1.0.3)
88
+ dm-timestamps (1.2.0)
89
+ dm-core (~> 1.2.0)
90
+ dm-transactions (1.2.0)
91
+ dm-core (~> 1.2.0)
92
+ dm-types (1.2.1)
93
+ bcrypt-ruby (~> 3.0.0)
94
+ dm-core (~> 1.2.0)
95
+ fastercsv (~> 1.5.4)
96
+ json (~> 1.6.1)
97
+ multi_json (~> 1.0.3)
98
+ stringex (~> 1.3.0)
99
+ uuidtools (~> 2.1.2)
100
+ dm-validations (1.2.0)
101
+ dm-core (~> 1.2.0)
63
102
  erubis (2.7.0)
64
- factory_girl (2.3.1)
103
+ factory_girl (2.3.2)
65
104
  activesupport
105
+ fastercsv (1.5.4)
66
106
  ffi (1.0.11)
67
107
  file-spec (0.4.0)
68
108
  activesupport (>= 3.0.1)
@@ -86,7 +126,7 @@ GEM
86
126
  sugar-high (>= 0.6.0)
87
127
  test-unit (>= 2.0.1)
88
128
  git (1.2.5)
89
- haml (3.1.3)
129
+ haml (3.1.4)
90
130
  hashie (1.2.0)
91
131
  hike (1.2.1)
92
132
  i18n (0.6.0)
@@ -94,7 +134,7 @@ GEM
94
134
  bundler (~> 1.0)
95
135
  git (>= 1.2.5)
96
136
  rake
97
- json (1.6.1)
137
+ json (1.6.2)
98
138
  json_pure (1.6.1)
99
139
  launchy (2.0.5)
100
140
  addressable (~> 2.2.6)
@@ -111,9 +151,21 @@ GEM
111
151
  mime-types (1.17.2)
112
152
  mocha (0.10.0)
113
153
  metaclass (~> 0.0.1)
114
- multi_json (1.0.3)
154
+ mongo (1.4.0)
155
+ bson (= 1.4.0)
156
+ mongo_mapper (0.10.1)
157
+ activemodel (~> 3.0)
158
+ activesupport (~> 3.0)
159
+ plucky (~> 0.4.0)
160
+ mongoid (2.3.4)
161
+ activemodel (~> 3.1)
162
+ mongo (~> 1.3)
163
+ tzinfo (~> 0.3.22)
164
+ multi_json (1.0.4)
115
165
  nokogiri (1.5.0)
116
166
  orm_adapter (0.0.5)
167
+ plucky (0.4.3)
168
+ mongo (~> 1.3)
117
169
  polyglot (0.3.3)
118
170
  rack (1.3.5)
119
171
  rack-cache (1.1)
@@ -169,11 +221,11 @@ GEM
169
221
  activesupport (~> 3.0)
170
222
  railties (~> 3.0)
171
223
  rspec (~> 2.7.0)
172
- rubyzip (0.9.4)
173
- selenium-webdriver (2.13.0)
224
+ rubyzip (0.9.5)
225
+ selenium-webdriver (2.14.0)
174
226
  childprocess (>= 0.2.1)
175
227
  ffi (~> 1.0.9)
176
- json_pure
228
+ multi_json (~> 1.0.4)
177
229
  rubyzip
178
230
  spork (0.8.5)
179
231
  sprockets (2.0.3)
@@ -181,18 +233,20 @@ GEM
181
233
  rack (~> 1.0)
182
234
  tilt (~> 1.1, != 1.3.0)
183
235
  sqlite3 (1.3.4)
236
+ stringex (1.3.0)
184
237
  sugar-high (0.6.0)
185
238
  activesupport (>= 3.0.1)
186
- sweetloader (0.1.1)
239
+ sweetloader (0.1.5)
187
240
  activesupport (>= 3.0.1)
188
241
  i18n
189
- test-unit (2.4.1)
242
+ test-unit (2.4.2)
190
243
  thor (0.14.6)
191
244
  tilt (1.3.3)
192
245
  treetop (1.4.10)
193
246
  polyglot
194
247
  polyglot (>= 0.3.1)
195
248
  tzinfo (0.3.31)
249
+ uuidtools (2.1.2)
196
250
  warden (1.1.0)
197
251
  rack (>= 1.0)
198
252
  xpath (0.1.4)
@@ -202,11 +256,13 @@ PLATFORMS
202
256
  ruby
203
257
 
204
258
  DEPENDENCIES
259
+ activerecord (>= 3)
205
260
  bundler (>= 1.1.rc)
206
261
  cancan (>= 1.4)
207
262
  capybara
208
263
  cutter
209
264
  database_cleaner
265
+ datamapper (>= 1.1)
210
266
  decent_exposure
211
267
  devise (>= 1.4)
212
268
  factory_girl
@@ -218,6 +274,8 @@ DEPENDENCIES
218
274
  jeweler (>= 1.6.4)
219
275
  launchy
220
276
  mocha
277
+ mongo_mapper (>= 0.9)
278
+ mongoid (>= 2.2)
221
279
  rails (>= 3.0.1)
222
280
  rails-app-spec (>= 0.5.0)
223
281
  rake (>= 0.9.2.2)
@@ -228,4 +286,4 @@ DEPENDENCIES
228
286
  spork
229
287
  sqlite3
230
288
  sugar-high (>= 0.6.0)
231
- sweetloader (~> 0.1.0)
289
+ sweetloader (~> 0.1.5)
data/README.mdown CHANGED
@@ -1,18 +1,10 @@
1
1
  # CanTango Core
2
2
 
3
- CanTango is an advanced Access Control (permissions) system for Rails 3. It:
3
+ Core functionality for [CanTango](https://github.com/kristianmandrup/cantango)
4
4
 
5
- * extends "CanCan":http://github.com/ryanb/cancan and offers a more role oriented design
6
- * integrates with _role_ and _authentication_ systems in a non-intrusive manner
7
- * can _cache_ ability rules between requests for increased performance
8
- * can _store_ abilites in a permission store, including a YAML file, for easy administration
9
- * works well with multiple user accounts and sub applications
10
- * supports multiple "Devise":https://github.com/plataformatec/devise users
5
+ ## Status: Dec 1 2011
11
6
 
12
- *Will CanTango meet my Access Control (permission) requirements?*
13
-
14
- * "CanCan vs CanTango":https://github.com/kristianmandrup/cantango/wiki/CanCan-vs-CanTango
15
- * "CanTango overview":https://github.com/kristianmandrup/cantango/wiki
7
+ The *core* CanTango component is now almost fully spec'ed and functional. Core should not dependencies to any other CanTango components but should stand on its own. All other CanTango components can rely on core for "core" functionality :)
16
8
 
17
9
  ## Installation
18
10
 
@@ -21,13 +13,13 @@ If you require ruby 1.8.7 support, please help patch it and make a pull request
21
13
 
22
14
  ### Install in Ruby environment (or gem set)
23
15
 
24
- `gem install cantango`
16
+ `gem install cantango-core`
25
17
 
26
18
  ## Install in Rails application
27
19
 
28
20
  Insert into Gemfile of your Rails application:
29
21
 
30
- `gem 'cantango'`
22
+ `gem 'cantango-core'`
31
23
 
32
24
  If you want to live on the edge and use the latest master branch, use the `:git` option. To designate a specific branch, use the `:branch` option. You can also clone this project and reference your local copy (easier to debug/fix) by using the `:path` option (see *Bundler* documentation).
33
25
 
@@ -39,15 +31,25 @@ Run bundler in a terminal/console from the folder of your Gemfile (root folder o
39
31
 
40
32
  CanTango has now been split up into these logical components:
41
33
 
34
+ * [Cantango core](https://github.com/kristianmandrup/cantango-core)
42
35
  * [Cantango config](https://github.com/kristianmandrup/cantango-config)
43
36
  * [Cantango cache](https://github.com/kristianmandrup/cantango-cache)
44
37
  * [Cantango model](https://github.com/kristianmandrup/cantango-model)
45
38
  * [Cantango masquerade](https://github.com/kristianmandrup/cantango-masquerade)
39
+ * [Cantango roles](https://github.com/kristianmandrup/cantango-roles)
40
+
41
+ Engines (Ability executors):
46
42
 
47
- * [Cantango Permits](https://github.com/kristianmandrup/cantango-permits)
43
+ * [Permits](https://github.com/kristianmandrup/cantango-permits)
48
44
  * [Permit store](https://github.com/kristianmandrup/cantango-permit_store)
49
45
  * [Permissions](https://github.com/kristianmandrup/cantango-permissions)
50
46
 
47
+ Cantango:
48
+
49
+ * [Cantango](https://github.com/kristianmandrup/cantango)
50
+
51
+ Currently the _cantango-1x_ branch
52
+
51
53
  ## Quickstart
52
54
 
53
55
  See the [Quickstart guide](https://github.com/kristianmandrup/cantango/wiki/Quickstart) in the wiki.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -4,17 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{cantango-core}
8
- s.version = "0.1.2"
7
+ s.name = "cantango-core"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Kristian Mandrup}, %q{Stanislaw Pankevich}]
12
- s.date = %q{2011-11-25}
13
- s.description = %q{Define your permission rules as role- or role group specific permits.
14
- Integrates well with multiple Devise user acounts.
15
- Includes rules caching.
16
- Store permissions in yaml file or key-value store}
17
- s.email = %q{kmandrup@gmail.com, s.pankevich@gmail.com}
11
+ s.authors = ["Kristian Mandrup", "Stanislaw Pankevich"]
12
+ s.date = "2011-12-01"
13
+ s.description = "Define your permission rules as role- or role group specific permits.\nIntegrates well with multiple Devise user acounts.\nIncludes rules caching.\nStore permissions in yaml file or key-value store"
14
+ s.email = "kmandrup@gmail.com, s.pankevich@gmail.com"
18
15
  s.extra_rdoc_files = [
19
16
  "LICENSE.txt",
20
17
  "README.mdown"
@@ -31,20 +28,28 @@ Store permissions in yaml file or key-value store}
31
28
  "cantango-core.gemspec",
32
29
  "lib/cantango/ability.rb",
33
30
  "lib/cantango/ability/base.rb",
31
+ "lib/cantango/ability/base/callbacks.rb",
34
32
  "lib/cantango/ability/cache.rb",
35
33
  "lib/cantango/ability/cache/simple_key.rb",
36
34
  "lib/cantango/ability/executor.rb",
37
35
  "lib/cantango/ability/executor/base.rb",
38
- "lib/cantango/ability/executor/cache_mode.rb",
39
36
  "lib/cantango/ability/executor/modes.rb",
40
37
  "lib/cantango/ability/executor/no_cache_mode.rb",
41
38
  "lib/cantango/ability/helper.rb",
42
39
  "lib/cantango/ability/helper/account.rb",
43
40
  "lib/cantango/ability/helper/engine.rb",
44
- "lib/cantango/ability/helper/role.rb",
45
- "lib/cantango/ability/helper/role_group.rb",
46
41
  "lib/cantango/ability/helper/user.rb",
42
+ "lib/cantango/adaptor.rb",
43
+ "lib/cantango/adaptor/active_record.rb",
44
+ "lib/cantango/adaptor/data_mapper.rb",
45
+ "lib/cantango/adaptor/generic.rb",
46
+ "lib/cantango/adaptor/mongo.rb",
47
+ "lib/cantango/adaptor/mongo_mapper.rb",
48
+ "lib/cantango/adaptor/mongoid.rb",
49
+ "lib/cantango/adaptor/relational.rb",
50
+ "lib/cantango/cancan.rb",
47
51
  "lib/cantango/cancan/rule.rb",
52
+ "lib/cantango/cancan/rule_class.rb",
48
53
  "lib/cantango/core.rb",
49
54
  "lib/cantango/engine.rb",
50
55
  "lib/cantango/filter.rb",
@@ -53,28 +58,12 @@ Store permissions in yaml file or key-value store}
53
58
  "lib/cantango/helpers/debug.rb",
54
59
  "lib/cantango/loader.rb",
55
60
  "lib/cantango/loader/yaml.rb",
56
- "lib/cantango/macros.rb",
57
- "lib/cantango/macros/account.rb",
58
- "lib/cantango/macros/user.rb",
59
61
  "lib/cantango/model.rb",
60
62
  "lib/cantango/model/guest.rb",
61
63
  "lib/cantango/rspec.rb",
62
64
  "lib/cantango/rspec/config.rb",
63
65
  "lib/cantango/rspec/matchers.rb",
64
66
  "lib/cantango/rspec/matchers/be_allowed_to.rb",
65
- "lib/cantango/rules.rb",
66
- "lib/cantango/rules/adaptor.rb",
67
- "lib/cantango/rules/adaptor/active_record.rb",
68
- "lib/cantango/rules/adaptor/data_mapper.rb",
69
- "lib/cantango/rules/adaptor/generic.rb",
70
- "lib/cantango/rules/adaptor/mongo.rb",
71
- "lib/cantango/rules/adaptor/mongo_mapper.rb",
72
- "lib/cantango/rules/adaptor/mongoid.rb",
73
- "lib/cantango/rules/adaptor/relational.rb",
74
- "lib/cantango/rules/dsl.rb",
75
- "lib/cantango/rules/relation.rb",
76
- "lib/cantango/rules/rule_class.rb",
77
- "lib/cantango/rules/scope.rb",
78
67
  "lib/cantango/scope.rb",
79
68
  "lib/cantango/scope/ability.rb",
80
69
  "lib/generators/cantango/install/install_generator.rb",
@@ -82,41 +71,42 @@ Store permissions in yaml file or key-value store}
82
71
  "lib/generators/cantango/install/templates/categories.yml",
83
72
  "lib/generators/cantango/install/templates/permissions.yml",
84
73
  "spec/cantango/ability/base_spec.rb",
85
- "spec/cantango/ability/cached_spec.rb",
86
- "spec/cantango/ability/executor/base2.rb",
74
+ "spec/cantango/ability/cache/simple_key_spec.rb",
87
75
  "spec/cantango/ability/executor/base_spec.rb",
88
- "spec/cantango/ability/executor/cache_mode_spec.rb",
76
+ "spec/cantango/ability/executor/custom_spec.rb",
89
77
  "spec/cantango/ability/executor/modes_spec.rb",
90
78
  "spec/cantango/ability/executor/no_cache_mode_spec.rb",
79
+ "spec/cantango/ability/helper/account_spec.rb",
80
+ "spec/cantango/ability/helper/engine_spec.rb",
81
+ "spec/cantango/ability/helper/user_spec.rb",
82
+ "spec/cantango/adaptor/active_record_spec.rb",
83
+ "spec/cantango/adaptor/data_mapper_spec.rb",
84
+ "spec/cantango/adaptor/mongo_mapper_spec.rb",
85
+ "spec/cantango/adaptor/mongoid_spec.rb",
91
86
  "spec/cantango/cancan/rule_spec.rb",
92
87
  "spec/cantango/core_spec.rb",
93
88
  "spec/cantango/engine_spec.rb",
94
89
  "spec/cantango/filter/base_spec.rb",
95
90
  "spec/cantango/helpers/debug_spec.rb",
96
91
  "spec/cantango/loader/yaml_spec.rb",
97
- "spec/cantango/macros/account_spec.rb",
98
- "spec/cantango/macros/user_spec.rb",
92
+ "spec/cantango/model/guest_spec.rb",
99
93
  "spec/cantango/rspec/be_allowed_to_spec.rb",
100
- "spec/cantango/rules/adaptor/active_record_spec.rb",
101
- "spec/cantango/rules/adaptor/data_mapper_spec.rb",
102
- "spec/cantango/rules/adaptor/mongo_mapper_spec.rb",
103
- "spec/cantango/rules/adaptor/mongoid_spec.rb",
104
- "spec/cantango/rules/adaptor_spec.rb",
105
- "spec/cantango/rules/dsl_spec.rb",
106
- "spec/cantango/rules/relation_spec.rb",
107
- "spec/cantango/rules/rule_class_spec.rb",
108
- "spec/cantango/rules/scope_spec.rb",
109
- "spec/cantango/rules_spec.rb",
110
94
  "spec/cantango/scope/ability_spec.rb",
111
95
  "spec/cantango_spec.rb",
96
+ "spec/fixtures/models.rb",
97
+ "spec/fixtures/models/account.rb",
98
+ "spec/fixtures/models/admin.rb",
99
+ "spec/fixtures/models/admin_account.rb",
100
+ "spec/fixtures/models/items.rb",
101
+ "spec/fixtures/models/user.rb",
112
102
  "spec/generators/cantango/install_generator_spec.rb",
113
103
  "spec/spec_helper.rb"
114
104
  ]
115
- s.homepage = %q{http://github.com/kristianmandrup/cantango}
116
- s.licenses = [%q{MIT}]
117
- s.require_paths = [%q{lib}]
118
- s.rubygems_version = %q{1.8.6}
119
- s.summary = %q{CanCan extension with role oriented permission management and more}
105
+ s.homepage = "http://github.com/kristianmandrup/cantango"
106
+ s.licenses = ["MIT"]
107
+ s.require_paths = ["lib"]
108
+ s.rubygems_version = "1.8.10"
109
+ s.summary = "CanCan extension with role oriented permission management and more"
120
110
 
121
111
  if s.respond_to? :specification_version then
122
112
  s.specification_version = 3
@@ -125,7 +115,7 @@ Store permissions in yaml file or key-value store}
125
115
  s.add_runtime_dependency(%q<rails>, [">= 3.0.1"])
126
116
  s.add_runtime_dependency(%q<cancan>, [">= 1.4"])
127
117
  s.add_runtime_dependency(%q<sugar-high>, [">= 0.6.0"])
128
- s.add_runtime_dependency(%q<sweetloader>, ["~> 0.1.0"])
118
+ s.add_runtime_dependency(%q<sweetloader>, ["~> 0.1.5"])
129
119
  s.add_runtime_dependency(%q<hashie>, [">= 0"])
130
120
  s.add_development_dependency(%q<rspec-rails>, [">= 2.6.1"])
131
121
  s.add_development_dependency(%q<forgery>, [">= 0.3"])
@@ -140,7 +130,7 @@ Store permissions in yaml file or key-value store}
140
130
  s.add_dependency(%q<rails>, [">= 3.0.1"])
141
131
  s.add_dependency(%q<cancan>, [">= 1.4"])
142
132
  s.add_dependency(%q<sugar-high>, [">= 0.6.0"])
143
- s.add_dependency(%q<sweetloader>, ["~> 0.1.0"])
133
+ s.add_dependency(%q<sweetloader>, ["~> 0.1.5"])
144
134
  s.add_dependency(%q<hashie>, [">= 0"])
145
135
  s.add_dependency(%q<rspec-rails>, [">= 2.6.1"])
146
136
  s.add_dependency(%q<forgery>, [">= 0.3"])
@@ -156,7 +146,7 @@ Store permissions in yaml file or key-value store}
156
146
  s.add_dependency(%q<rails>, [">= 3.0.1"])
157
147
  s.add_dependency(%q<cancan>, [">= 1.4"])
158
148
  s.add_dependency(%q<sugar-high>, [">= 0.6.0"])
159
- s.add_dependency(%q<sweetloader>, ["~> 0.1.0"])
149
+ s.add_dependency(%q<sweetloader>, ["~> 0.1.5"])
160
150
  s.add_dependency(%q<hashie>, [">= 0"])
161
151
  s.add_dependency(%q<rspec-rails>, [">= 2.6.1"])
162
152
  s.add_dependency(%q<forgery>, [">= 0.3"])
@@ -0,0 +1,37 @@
1
+ module CanTango::Ability
2
+ class Base
3
+ module Callbacks
4
+ module ClassMethods
5
+ [:after, :before].each do |type|
6
+ class_eval %{
7
+ def #{type}_execute_callbacks
8
+ @#{type}_execute_callbacks ||= []
9
+ end
10
+
11
+ def #{type}_execute *callbacks
12
+ @#{type}_execute_callbacks = callbacks.flatten
13
+ end
14
+ }
15
+ end
16
+ end
17
+
18
+ # should execute :after_execute callbacks
19
+ def after_execute
20
+ execute_engines! if engines_on?
21
+
22
+ self.class.after_execute_callbacks.each {|callback| send(callback) }
23
+ end
24
+
25
+ # should execute :before_execute callbacks
26
+ def before_execute
27
+ self.class.before_execute_callbacks.each {|callback| send(callback) }
28
+ end
29
+
30
+ def within_callbacks &block
31
+ before_execute
32
+ yield
33
+ after_execute
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,6 +1,8 @@
1
1
  module CanTango
2
2
  module Ability
3
3
  class Base
4
+ autoload_modules :Callbacks
5
+
4
6
  include CanCan::Ability
5
7
 
6
8
  attr_reader :options, :candidate
@@ -10,11 +12,23 @@ module CanTango
10
12
  def initialize candidate, options = {}
11
13
  raise "Candidate must be something!" if !candidate
12
14
  @candidate, @options = candidate, options
15
+ execute!
16
+ end
17
+
18
+ def execute!
19
+ within_callbacks do
20
+ clear_rules!
21
+ permit_rules
22
+ end
23
+ end
13
24
 
14
- clear_rules!
15
- permit_rules
25
+ def within_callbacks &block
26
+ yield
27
+ end
16
28
 
17
- execute_engines! if engines_on?
29
+ # overriden by Engine helper
30
+ def engines_on?
31
+ false
18
32
  end
19
33
 
20
34
  def cached?
@@ -37,9 +51,8 @@ module CanTango
37
51
  @session = options[:session] || {} # seperate session cache for each type of user?
38
52
  end
39
53
 
54
+ # overriden by Masquerade helper
40
55
  def subject
41
- return candidate.active_user if masquerade_user?
42
- return candidate.active_account if masquerade_account?
43
56
  candidate
44
57
  end
45
58
 
@@ -47,9 +60,9 @@ module CanTango
47
60
  CanTango.config
48
61
  end
49
62
 
50
- Helper.modules.each do |name|
51
- include "CanTango::Ability::Helper::#{name.to_s.camelize}".constantize
52
- end
63
+ # Helper.modules.each do |name|
64
+ # include "CanTango::Ability::Helper::#{name.to_s.camelize}".constantize
65
+ # end
53
66
 
54
67
  protected
55
68
 
@@ -1,7 +1,7 @@
1
1
  module CanTango
2
2
  module Ability
3
3
  module Cache
4
- autoload_modules :Key
4
+ autoload_modules :SimpleKey
5
5
  end
6
6
  end
7
7
  end
@@ -31,20 +31,20 @@ module CanTango
31
31
  rules.compact!
32
32
  end
33
33
 
34
- def get_ability mode
35
- ability_class_for(mode).new candidate, options
34
+ def ability_mode_executor_for mode
35
+ ability_mode_executor_class_for(mode).new candidate, options
36
36
  end
37
37
 
38
- def ability_class_for mode
39
- mode == :cache ? CanTango::Ability::Cached : CanTango::Ability::NonCached
38
+ def ability_mode_executor_class_for mode
39
+ "CanTango::Ability::Executor::#{mode.to_s.camelize}Mode".constantize
40
40
  end
41
41
 
42
42
  def mode? mode
43
43
  modes.include?(mode)
44
44
  end
45
-
45
+
46
46
  def modes
47
- CanTango.config.ability.modes
47
+ @modes ||= options[:modes] || []
48
48
  end
49
49
  end
50
50
  end
@@ -1,15 +1,11 @@
1
1
  module CanTango
2
2
  module Ability
3
3
  module Executor
4
- class NonCachedMode < Base
4
+ class NoCacheMode < Base
5
5
  protected
6
6
 
7
7
  def start_execute
8
- debug "Executing non-cached Ability"
9
- end
10
-
11
- def end_execute
12
- debug "DONE"
8
+ debug "Executing Ability in :no_cache mode"
13
9
  end
14
10
  end
15
11
  end
@@ -1,7 +1,7 @@
1
1
  module CanTango
2
2
  module Ability
3
3
  module Executor
4
- autoload_modules :Base, :CacheMode, :NoCacheMode, :Modes
4
+ autoload_modules :Base, :NoCacheMode, :Modes
5
5
  end
6
6
  end
7
7
  end
@@ -1,13 +1,9 @@
1
- module CanTango
2
- class Ability
3
- module Helper
4
- module Account
5
- def user_account
6
- return subject.active_account if subject.respond_to? :active_account
7
- subject
8
- end
9
- alias_method :account, :user_account
10
- end
1
+ module CanTango::Ability::Helper
2
+ module Account
3
+ def account
4
+ return subject.active_account if subject.respond_to? :active_account
5
+ return subject.account if subject.respond_to? :account
6
+ subject
11
7
  end
12
8
  end
13
9
  end