cantango 0.9.3.2 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/README.textile +11 -9
  2. data/VERSION +1 -1
  3. data/cantango.gemspec +24 -3
  4. data/lib/cantango/ability/cache/key.rb +6 -2
  5. data/lib/cantango/ability/cache/reader.rb +3 -0
  6. data/lib/cantango/ability/cache/session_cache.rb +7 -3
  7. data/lib/cantango/ability/cache/writer.rb +8 -2
  8. data/lib/cantango/ability/cache.rb +25 -8
  9. data/lib/cantango/ability/cache_helpers.rb +4 -13
  10. data/lib/cantango/ability/cached_executor.rb +0 -0
  11. data/lib/cantango/ability/engine_helpers.rb +4 -1
  12. data/lib/cantango/ability/executor.rb +67 -0
  13. data/lib/cantango/ability/permission_helpers.rb +0 -1
  14. data/lib/cantango/ability.rb +1 -1
  15. data/lib/cantango/cached_ability.rb +3 -2
  16. data/lib/cantango/configuration/engines/cache.rb +0 -3
  17. data/lib/cantango/configuration/engines/engine.rb +5 -0
  18. data/lib/cantango/configuration/engines/permission.rb +5 -4
  19. data/lib/cantango/configuration/engines/permit.rb +0 -5
  20. data/lib/cantango/configuration/engines/user_ac.rb +6 -3
  21. data/lib/cantango/configuration/models/active_record.rb +11 -0
  22. data/lib/cantango/configuration/models/data_mapper.rb +12 -0
  23. data/lib/cantango/configuration/models/generic.rb +12 -0
  24. data/lib/cantango/configuration/models/mongo.rb +12 -0
  25. data/lib/cantango/configuration/models/mongo_mapper.rb +11 -0
  26. data/lib/cantango/configuration/models/mongoid.rb +13 -0
  27. data/lib/cantango/configuration/models.rb +27 -2
  28. data/lib/cantango/configuration/permits.rb +2 -1
  29. data/lib/cantango/configuration.rb +14 -0
  30. data/lib/cantango/engine.rb +5 -19
  31. data/lib/cantango/model/scope.rb +19 -5
  32. data/lib/cantango/permission_engine/collector.rb +3 -0
  33. data/lib/cantango/permission_engine/evaluator.rb +5 -0
  34. data/lib/cantango/permission_engine/factory.rb +3 -0
  35. data/lib/cantango/permission_engine/loader/permissions.rb +7 -8
  36. data/lib/cantango/permission_engine/store.rb +0 -1
  37. data/lib/cantango/permission_engine/yaml_store.rb +15 -4
  38. data/lib/cantango/permission_engine.rb +21 -4
  39. data/lib/cantango/permit_engine/factory.rb +10 -4
  40. data/lib/cantango/permit_engine.rb +39 -9
  41. data/lib/cantango/permits/account_permit/builder.rb +6 -2
  42. data/lib/cantango/{user_ac_engine → permits}/executor.rb +28 -30
  43. data/lib/cantango/permits/permit/class_methods.rb +21 -0
  44. data/lib/cantango/permits/permit/execute.rb +81 -0
  45. data/lib/cantango/permits/permit/license.rb +26 -0
  46. data/lib/cantango/permits/permit.rb +19 -138
  47. data/lib/cantango/permits/role_group_permit/builder.rb +5 -1
  48. data/lib/cantango/permits/role_group_permit.rb +3 -3
  49. data/lib/cantango/permits/role_permit/builder.rb +4 -0
  50. data/lib/cantango/permits/user_permit/builder.rb +5 -1
  51. data/lib/cantango/permits/user_permit.rb +1 -1
  52. data/lib/cantango/permits.rb +1 -0
  53. data/lib/cantango/rails/engine.rb +0 -3
  54. data/lib/cantango/rails/helpers/base_helper.rb +1 -1
  55. data/lib/cantango/rails/helpers/rest_helper.rb +1 -1
  56. data/lib/cantango/rules/adaptor/active_record.rb +1 -4
  57. data/lib/cantango/rules/adaptor/data_mapper.rb +11 -0
  58. data/lib/cantango/rules/adaptor/mongo.rb +19 -0
  59. data/lib/cantango/rules/adaptor/mongo_mapper.rb +10 -0
  60. data/lib/cantango/rules/adaptor/mongoid.rb +1 -5
  61. data/lib/cantango/rules/adaptor/relational.rb +13 -0
  62. data/lib/cantango/rules/adaptor.rb +12 -7
  63. data/lib/cantango/rules/user_relation.rb +1 -2
  64. data/lib/cantango/user_ac_engine.rb +25 -7
  65. data/lib/cantango.rb +2 -0
  66. data/spec/cantango/ability/executor_spec.rb +67 -0
  67. data/spec/cantango/ability_executor/cached_only_spec.rb +1 -0
  68. data/spec/cantango/model/scope_spec.rb +11 -0
  69. data/spec/cantango/models/items.rb +5 -0
  70. data/spec/cantango/permission_engine_cached_spec.rb +51 -0
  71. data/spec/cantango/permission_engine_spec.rb +55 -0
  72. data/spec/cantango/permit_engine_cached_spec.rb +56 -0
  73. data/spec/cantango/permit_engine_spec.rb +57 -1
  74. data/spec/cantango/permits/executor_cached_spec.rb +0 -0
  75. data/spec/cantango/permits/executor_spec.rb +68 -0
  76. data/spec/cantango/user_ac_engine_cached_spec.rb +64 -0
  77. data/spec/cantango/user_ac_engine_spec.rb +14 -2
  78. data/spec/fixtures/models/items.rb +3 -0
  79. data/spec/fixtures/models/user.rb +18 -0
  80. metadata +55 -34
data/README.textile CHANGED
@@ -35,17 +35,17 @@ Run bundler in a terminal/console from the folder of your Gemfile (root folder o
35
35
 
36
36
  @$ bundle@
37
37
 
38
- h2. Update Oct 29, 2011
38
+ h2. Update Nov 2, 2011
39
39
 
40
- Versions *0.9+* have naming bug. Please use version 0.8.9 for now.
40
+ Version 0.9.4 has been released with the following featuring and improvements:
41
41
 
42
- New features:
42
+ * Redesign of Cache and Ability execution
43
+ * Caching at the individual engine level that can be switched (configured) on/off
44
+ * Individual caching for each type of Permit in the Permit engine
45
+ * Each engine return a set of rules which are merged into one rule set for that particular execution mode
46
+ * Caching for the new User AC engine
43
47
 
44
- * Model AC filters and scopes
45
- * Engine _:user_ac_ (User Access Control)
46
- * Cache and No-Cache modes for Ability, run in succession and rule results merged
47
-
48
- The :user_ac engine is a port of the Permission system from the _Rails in Action_ book.
48
+ The :user_ac engine is a port of the Permission system from the _Rails in Action_ book.
49
49
  With this engine a user can have many permissions defined, where each such permission is a persisted Permission model instance that describes a 'can' action on a specific type of object.
50
50
 
51
51
  The new modal Ability model allows you to define rules that are run in Cache mode and others that can be run in no-cache mode. This enables you to circumvent the previos restriction that didn't allow you to use normal conditional ruby logic outside blocks if you enabled caching.
@@ -53,16 +53,18 @@ The new modal Ability model allows you to define rules that are run in Cache mod
53
53
  <pre>
54
54
  class UserPermit < CanTango::UserPermit
55
55
  def static_rules
56
- ...
56
+ can :access, Article
57
57
  end
58
58
 
59
59
  module Cached
60
60
  def permit_rules
61
+ can :read, Project
61
62
  end
62
63
  end
63
64
 
64
65
  module NonCached
65
66
  def permit_rules
67
+ can :edit, Article
66
68
  end
67
69
  end
68
70
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.3.2
1
+ 0.9.4
data/cantango.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cantango}
8
- s.version = "0.9.3.2"
8
+ s.version = "0.9.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Kristian Mandrup}, %q{Stanislaw Pankevich}]
12
- s.date = %q{2011-10-29}
12
+ s.date = %q{2011-11-02}
13
13
  s.description = %q{Define your permission rules as role- or role group specific permits.
14
14
  Integrates well with multiple Devise user acounts.
15
15
  Includes rules caching.
@@ -41,7 +41,9 @@ Store permissions in yaml file or key-value store}
41
41
  "lib/cantango/ability/cache/session_cache.rb",
42
42
  "lib/cantango/ability/cache/writer.rb",
43
43
  "lib/cantango/ability/cache_helpers.rb",
44
+ "lib/cantango/ability/cached_executor.rb",
44
45
  "lib/cantango/ability/engine_helpers.rb",
46
+ "lib/cantango/ability/executor.rb",
45
47
  "lib/cantango/ability/masquerade_helpers.rb",
46
48
  "lib/cantango/ability/permission_helpers.rb",
47
49
  "lib/cantango/ability/permit_helpers.rb",
@@ -89,6 +91,12 @@ Store permissions in yaml file or key-value store}
89
91
  "lib/cantango/configuration/guest.rb",
90
92
  "lib/cantango/configuration/hash_registry.rb",
91
93
  "lib/cantango/configuration/models.rb",
94
+ "lib/cantango/configuration/models/active_record.rb",
95
+ "lib/cantango/configuration/models/data_mapper.rb",
96
+ "lib/cantango/configuration/models/generic.rb",
97
+ "lib/cantango/configuration/models/mongo.rb",
98
+ "lib/cantango/configuration/models/mongo_mapper.rb",
99
+ "lib/cantango/configuration/models/mongoid.rb",
92
100
  "lib/cantango/configuration/modes.rb",
93
101
  "lib/cantango/configuration/permit_registry.rb",
94
102
  "lib/cantango/configuration/permits.rb",
@@ -160,11 +168,15 @@ Store permissions in yaml file or key-value store}
160
168
  "lib/cantango/permits/account_permit.rb",
161
169
  "lib/cantango/permits/account_permit/builder.rb",
162
170
  "lib/cantango/permits/account_permit/finder.rb",
171
+ "lib/cantango/permits/executor.rb",
163
172
  "lib/cantango/permits/license.rb",
164
173
  "lib/cantango/permits/license/loader.rb",
165
174
  "lib/cantango/permits/license/rules.rb",
166
175
  "lib/cantango/permits/macros.rb",
167
176
  "lib/cantango/permits/permit.rb",
177
+ "lib/cantango/permits/permit/class_methods.rb",
178
+ "lib/cantango/permits/permit/execute.rb",
179
+ "lib/cantango/permits/permit/license.rb",
168
180
  "lib/cantango/permits/role_group_permit.rb",
169
181
  "lib/cantango/permits/role_group_permit/builder.rb",
170
182
  "lib/cantango/permits/role_group_permit/finder.rb",
@@ -191,14 +203,17 @@ Store permissions in yaml file or key-value store}
191
203
  "lib/cantango/rules.rb",
192
204
  "lib/cantango/rules/adaptor.rb",
193
205
  "lib/cantango/rules/adaptor/active_record.rb",
206
+ "lib/cantango/rules/adaptor/data_mapper.rb",
194
207
  "lib/cantango/rules/adaptor/generic.rb",
208
+ "lib/cantango/rules/adaptor/mongo.rb",
209
+ "lib/cantango/rules/adaptor/mongo_mapper.rb",
195
210
  "lib/cantango/rules/adaptor/mongoid.rb",
211
+ "lib/cantango/rules/adaptor/relational.rb",
196
212
  "lib/cantango/rules/dsl.rb",
197
213
  "lib/cantango/rules/rule_class.rb",
198
214
  "lib/cantango/rules/scope.rb",
199
215
  "lib/cantango/rules/user_relation.rb",
200
216
  "lib/cantango/user_ac_engine.rb",
201
- "lib/cantango/user_ac_engine/executor.rb",
202
217
  "lib/cantango/users.rb",
203
218
  "lib/cantango/users/macros.rb",
204
219
  "lib/cantango/users/masquerade.rb",
@@ -299,6 +314,7 @@ Store permissions in yaml file or key-value store}
299
314
  "spec/cantango/ability/cache/session_cache_spec.rb",
300
315
  "spec/cantango/ability/cache/writer_spec.rb",
301
316
  "spec/cantango/ability/cache_spec.rb",
317
+ "spec/cantango/ability/executor_spec.rb",
302
318
  "spec/cantango/ability_executor/cached_only_spec.rb",
303
319
  "spec/cantango/ability_executor_spec.rb",
304
320
  "spec/cantango/ability_filters_spec.rb",
@@ -365,6 +381,7 @@ Store permissions in yaml file or key-value store}
365
381
  "spec/cantango/permission_engine/store_spec.rb",
366
382
  "spec/cantango/permission_engine/user_permission_store_spec.rb",
367
383
  "spec/cantango/permission_engine/yaml_store_spec.rb",
384
+ "spec/cantango/permission_engine_cached_spec.rb",
368
385
  "spec/cantango/permission_engine_spec.rb",
369
386
  "spec/cantango/permit_engine/account_permit_spec.rb",
370
387
  "spec/cantango/permit_engine/builder/role_group_permits_spec.rb",
@@ -378,10 +395,14 @@ Store permissions in yaml file or key-value store}
378
395
  "spec/cantango/permit_engine/role_group_permit_spec.rb",
379
396
  "spec/cantango/permit_engine/role_permit_spec.rb",
380
397
  "spec/cantango/permit_engine/user_permit_spec.rb",
398
+ "spec/cantango/permit_engine_cached_spec.rb",
381
399
  "spec/cantango/permit_engine_spec.rb",
400
+ "spec/cantango/permits/executor_cached_spec.rb",
401
+ "spec/cantango/permits/executor_spec.rb",
382
402
  "spec/cantango/permits/macros_spec.rb",
383
403
  "spec/cantango/permits/permit_spec.rb",
384
404
  "spec/cantango/rules_spec.rb",
405
+ "spec/cantango/user_ac_engine_cached_spec.rb",
385
406
  "spec/cantango/user_ac_engine_spec.rb",
386
407
  "spec/cantango_spec.rb",
387
408
  "spec/devise-dummy/Rakefile",
@@ -7,7 +7,7 @@ module CanTango
7
7
  def initialize user, subject = nil, method_names = nil
8
8
  @user = user
9
9
  @subject = subject || user
10
- @method_names = method_names
10
+ @method_names = method_names if method_names
11
11
  end
12
12
 
13
13
  def method_names
@@ -19,7 +19,7 @@ module CanTango
19
19
  end
20
20
 
21
21
  def value
22
- raise "No key could be generated for #{user} and #{subject}" if hash_values.empty?
22
+ raise "No key could be generated for User:#{user.inspect} and Subject:#{subject} - key field: #{user_key_field}" if hash_values.empty?
23
23
  @value ||= hash_values.hash
24
24
  end
25
25
 
@@ -28,6 +28,10 @@ module CanTango
28
28
  session[:cache_key] && (value == session[:cache_key].value)
29
29
  end
30
30
 
31
+ def to_s
32
+ "key hash: #{value}"
33
+ end
34
+
31
35
  protected
32
36
 
33
37
  def hash_values
@@ -2,6 +2,8 @@ module CanTango
2
2
  class Ability
3
3
  class Cache
4
4
  class Reader
5
+ include CanTango::Helpers::Debug
6
+
5
7
  attr_reader :cache
6
8
 
7
9
  def initialize cache
@@ -9,6 +11,7 @@ module CanTango
9
11
  end
10
12
 
11
13
  def prepared_rules
14
+ debug "reading rules from cache: #{cache.key}"
12
15
  cache.compile_on? ? compiler.decompile!(loaded_rules) : loaded_rules
13
16
  end
14
17
 
@@ -3,6 +3,7 @@ module CanTango
3
3
  class Cache
4
4
  class SessionCache < BaseCache
5
5
  attr_accessor :session
6
+ attr_reader :key
6
7
 
7
8
  # will be called with :session => session (pointing to user session)
8
9
  def initialize name, options = {}
@@ -10,11 +11,15 @@ module CanTango
10
11
  @cache = cache
11
12
  @cache.configure_with :type => :memory
12
13
  raise "SessionCache must be initialized with a :session option" if !session
13
- session[:rules_cache] = @cache
14
+ session[cache_key] = @cache
15
+ end
16
+
17
+ def cache_key
18
+ @cache_key ||= :rules_cache
14
19
  end
15
20
 
16
21
  def store
17
- session[:rules_cache]
22
+ session[cache_key]
18
23
  end
19
24
 
20
25
  def load key
@@ -31,7 +36,6 @@ module CanTango
31
36
 
32
37
  def cache
33
38
  CanTango::Cache::HashCache.instance
34
- # CanTango::Cache::MonetaCache.instance
35
39
  end
36
40
  end
37
41
  end
@@ -2,7 +2,11 @@ module CanTango
2
2
  class Ability
3
3
  class Cache
4
4
  class Writer
5
- attr_reader :cache
5
+ include CanTango::Helpers::Debug
6
+
7
+ attr_reader :cache, :cache_key
8
+
9
+ delegate :cache_key, :to => :cache
6
10
 
7
11
  def initialize cache
8
12
  @cache = cache
@@ -10,8 +14,10 @@ module CanTango
10
14
 
11
15
  def save key, rules
12
16
  cache.invalidate!
17
+ return if prepared_rules.blank?
18
+ debug "writing #{prepared_rules.size} rules to cache: #{key}"
13
19
  cache.rules_cache.save cache.key, prepared_rules
14
- session[:cache_key] = cache.key if session
20
+ session[cache_key] = cache.key if session
15
21
  end
16
22
 
17
23
  protected
@@ -3,22 +3,39 @@ module CanTango
3
3
  class Cache
4
4
  autoload_modules :BaseCache, :SessionCache, :Reader, :Writer, :RulesCache, :Key
5
5
 
6
+ include CanTango::Helpers::Debug
7
+ include CanTango::Helpers::RoleMethods
8
+
6
9
  attr_reader :rules_cached, :ability
10
+ attr_writer :key_method_names, :cache_key
11
+
12
+ delegate :session, :cached?, :to => :ability
7
13
 
8
- def initialize ability
14
+ def initialize ability, options = {}
9
15
  @ability = ability
16
+ @cache_key = options[:cache_key]
17
+ @key_method_names = options[:key_method_names]
18
+ debug "Creating cache with key: #{cache_key.inspect} on #{key_method_names.inspect}"
19
+ end
20
+
21
+ def empty?
22
+ cached_rules.blank?
23
+ end
24
+
25
+ def key_method_names
26
+ @key_method_names ||= [roles_list_meth, role_groups_list_meth]
10
27
  end
11
28
 
12
- def session
13
- ability.session
29
+ def cache_key
30
+ @cache_key ||= :cache
14
31
  end
15
32
 
16
33
  def cache_rules!
17
- writer.save key, reader.prepared_rules
34
+ writer.save(key, reader.prepared_rules) if cached?
18
35
  end
19
36
 
20
37
  def cached_rules
21
- @rules ||= reader.prepared_rules
38
+ @rules ||= reader.prepared_rules if cached?
22
39
  end
23
40
 
24
41
  def compiler
@@ -34,11 +51,11 @@ module CanTango
34
51
  end
35
52
 
36
53
  def cached_rules?
37
- key.same? session
54
+ key.same?(session) && cached?
38
55
  end
39
56
 
40
57
  def key
41
- @key ||= Key.new ability.user, ability.subject
58
+ @key ||= Key.new ability.user, ability.subject, key_method_names
42
59
  end
43
60
 
44
61
  def rules_cache
@@ -47,7 +64,7 @@ module CanTango
47
64
 
48
65
  def invalidate!
49
66
  raise "no session" if !session
50
- rules_cache.invalidate! session[:cache_key]
67
+ rules_cache.invalidate! session[cache_key]
51
68
  end
52
69
 
53
70
  def compile_on?
@@ -1,21 +1,12 @@
1
1
  module CanTango
2
2
  class Ability
3
3
  module CacheHelpers
4
+ include CanTango::Helpers::RoleMethods
4
5
 
5
- def cached_rules?
6
- cache.key.same?(session)
7
- end
8
-
9
- def cache_rules!
10
- cache.cache_rules!
11
- end
12
-
13
- def cached_rules
14
- cache.cached_rules
15
- end
6
+ delegate :cache_rules!, :cached_rules, :cached_rules?, :to => :cache
16
7
 
17
- def cache
18
- @cache ||= Cache.new self
8
+ def cache options = {}
9
+ @cache ||= CanTango::Ability::Cache.new self, options
19
10
  end
20
11
  end
21
12
  end
File without changes
@@ -2,7 +2,10 @@ module CanTango
2
2
  class Ability
3
3
  module EngineHelpers
4
4
  def execute_engines!
5
- each_engine {|engine| engine.new(self).execute! if engine }
5
+ each_engine do |engine|
6
+ engine_rules = engine.new(self).execute! if engine
7
+ @rules << engine_rules if !engine_rules.blank?
8
+ end
6
9
  end
7
10
 
8
11
  def each_engine &block
@@ -0,0 +1,67 @@
1
+ module CanTango
2
+ class Ability
3
+ module Executor
4
+ include CanTango::Helpers::Debug
5
+ include CanTango::Ability::CacheHelpers
6
+
7
+ delegate :session, :user, :subject, :candidate, :cached?, :to => :ability
8
+
9
+ def execute!
10
+ return if !valid?
11
+ start_execute
12
+ return cached_rules if cached? && cached_rules?
13
+
14
+ clear_rules!
15
+ permit_rules
16
+
17
+ cache_rules! if cached?
18
+ end_execute
19
+ rules
20
+ end
21
+
22
+ def rules
23
+ @rules ||= []
24
+ end
25
+
26
+ def clear_rules!
27
+ @rules ||= []
28
+ end
29
+
30
+ def permit_rules
31
+ raise NotImplementedError
32
+ end
33
+
34
+ def cache
35
+ @cache ||= CanTango::Ability::Cache.new self, :cache_key => cache_key, :key_method_names => key_method_names
36
+ end
37
+
38
+ def engine_name
39
+ :permit
40
+ end
41
+
42
+ def valid?
43
+ raise NotImplementedError
44
+ end
45
+
46
+ protected
47
+
48
+ def start_execute
49
+ debug "executing..."
50
+ end
51
+
52
+ def end_execute
53
+ debug "DONE"
54
+ end
55
+
56
+ def cache_key
57
+ raise NotImplementedError
58
+ end
59
+
60
+ def key_method_names
61
+ []
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+
@@ -9,4 +9,3 @@ module CanTango
9
9
  end
10
10
  end
11
11
  end
12
-
@@ -2,7 +2,7 @@ require 'cantango/permit_engine/util'
2
2
 
3
3
  module CanTango
4
4
  class Ability
5
- autoload_modules :Scope, :Cache
5
+ autoload_modules :Scope, :Cache, :Executor
6
6
  autoload_modules :MasqueradeHelpers, :PermitHelpers, :PermissionHelpers
7
7
  autoload_modules :UserHelpers, :RoleHelpers, :CacheHelpers, :EngineHelpers
8
8
 
@@ -6,13 +6,14 @@ module CanTango
6
6
  raise "Candidate must be something!" if !candidate
7
7
  @candidate, @options = candidate, options
8
8
 
9
- return if cached_rules?
9
+ # return if cached_rules?
10
10
 
11
11
  clear_rules!
12
12
  permit_rules
13
13
 
14
14
  execute_engines! if engines_on?
15
- cache_rules!
15
+
16
+ # cache_rules!
16
17
  end
17
18
 
18
19
  def cached?
@@ -1,10 +1,7 @@
1
- require 'singleton'
2
-
3
1
  module CanTango
4
2
  class Configuration
5
3
  class Engines
6
4
  class Cache < Engine
7
- include Singleton
8
5
 
9
6
  def compile state
10
7
  raise "Must be set to :on or :off" if ![:on, :off].include? state
@@ -1,7 +1,12 @@
1
+ require 'singleton'
2
+
1
3
  module CanTango
2
4
  class Configuration
3
5
  class Engines
4
6
  class Engine
7
+ include Singleton
8
+ include CanTango::Configuration::Modes
9
+
5
10
  def set state = :on
6
11
  raise ArgumentError, "Must be :on or :off" unless !state || [:on, :off].include?(state)
7
12
  @state = state || :on
@@ -4,9 +4,6 @@ module CanTango
4
4
  class Configuration
5
5
  class Engines
6
6
  class Permission < Engine
7
- include Singleton
8
- include CanTango::Configuration::Modes
9
-
10
7
  def modes
11
8
  @modes ||= [:cache]
12
9
  end
@@ -34,9 +31,13 @@ module CanTango
34
31
 
35
32
  private
36
33
 
34
+ def valid_mode_names
35
+ [:cache, :no_cache]
36
+ end
37
+
37
38
  def current_config_path
38
39
  @config_path ||= File.join(::Rails.root.to_s, 'config') if rails?
39
- @config_path or raise "Define path to config files dir!\n"
40
+ @config_path or raise "Define path to config files dir!\nCanTango.config.engine(:permission).config_path(dir_path)"
40
41
  end
41
42
 
42
43
  def rails?
@@ -1,12 +1,7 @@
1
- require 'singleton'
2
-
3
1
  module CanTango
4
2
  class Configuration
5
3
  class Engines
6
4
  class Permit < Engine
7
- include Singleton
8
- include CanTango::Configuration::Modes
9
-
10
5
  def on?
11
6
  @state ||= :on
12
7
  @state == :on
@@ -4,12 +4,15 @@ module CanTango
4
4
  class Configuration
5
5
  class Engines
6
6
  class UserAc < Engine
7
- include Singleton
8
- include CanTango::Configuration::Modes
9
-
10
7
  def modes
11
8
  @modes ||= [:no_cache]
12
9
  end
10
+
11
+ private
12
+
13
+ def valid_mode_names
14
+ [:cache, :no_cache]
15
+ end
13
16
  end
14
17
  end
15
18
  end
@@ -0,0 +1,11 @@
1
+ module CanTango
2
+ class Configuration
3
+ class Models
4
+ class ActiveRecord < Generic
5
+ def models
6
+ ActiveRecord::Base.descendants
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module CanTango
2
+ class Configuration
3
+ class Models
4
+ class DataMapper < Generic
5
+ def models
6
+ DataMapper::Resource.descendants
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,12 @@
1
+ module CanTango
2
+ class Configuration
3
+ class Models
4
+ class Generic
5
+ def available_models
6
+ models.map(&:name)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,12 @@
1
+ module CanTango
2
+ class Configuration
3
+ class Models
4
+ class Mongo
5
+ def available_models
6
+ models.map {|m| m.to_s.camelize }
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,11 @@
1
+ module CanTango
2
+ class Configuration
3
+ class Models
4
+ module MongoMapper < Mongo
5
+ def models
6
+ MongoMapper.database.collections
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module CanTango
2
+ class Configuration
3
+ class Models
4
+ class Mongoid < Mongo
5
+ def models
6
+ ::Mongoid.database.collections
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+