cantango-core 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.mdown +12 -34
- data/VERSION +1 -1
- data/cantango-core.gemspec +33 -16
- data/lib/cantango/ability/base.rb +8 -52
- data/lib/cantango/ability/cache/simple_key.rb +1 -0
- data/lib/cantango/ability/callbacks.rb +36 -0
- data/lib/cantango/ability/executor/base.rb +21 -46
- data/lib/cantango/ability/executor/modal.rb +46 -0
- data/lib/cantango/ability/executor.rb +24 -1
- data/lib/cantango/ability/mode/base.rb +32 -0
- data/lib/cantango/ability/mode/finder.rb +19 -0
- data/lib/cantango/ability/mode/no_cache.rb +8 -0
- data/lib/cantango/ability/mode.rb +7 -0
- data/lib/cantango/ability/rules.rb +24 -0
- data/lib/cantango/ability.rb +1 -6
- data/lib/cantango/adaptor/active_record.rb +1 -1
- data/lib/cantango/adaptor/data_mapper.rb +1 -1
- data/lib/cantango/adaptor/mongo.rb +1 -1
- data/lib/cantango/adaptor/mongo_mapper.rb +1 -1
- data/lib/cantango/adaptor/mongoid.rb +1 -1
- data/lib/cantango/adaptor.rb +24 -26
- data/lib/cantango/core.rb +1 -1
- data/lib/cantango/helpers/debug.rb +4 -2
- data/lib/cantango/loader/yaml.rb +5 -1
- data/spec/active_record/001_create_posters.rb +13 -0
- data/spec/active_record/002_create_users.rb +13 -0
- data/spec/cantango/ability/base_spec.rb +3 -6
- data/spec/cantango/ability/callbacks_spec.rb +48 -0
- data/spec/cantango/ability/executor/base_spec.rb +15 -14
- data/spec/cantango/ability/executor/custom_spec.rb +3 -3
- data/spec/cantango/ability/executor/modal_spec.rb +35 -0
- data/spec/cantango/ability/executor_spec.rb +29 -0
- data/spec/cantango/ability/mode/base_example.rb +28 -0
- data/spec/cantango/ability/mode/base_spec.rb +15 -0
- data/spec/cantango/ability/mode/no_cache_spec.rb +15 -0
- data/spec/cantango/ability/rules_spec.rb +48 -0
- data/spec/cantango/adaptor/active_record_spec.rb +11 -2
- data/spec/cantango/loader/yaml_spec.rb +9 -1
- data/spec/cantango/rspec/be_allowed_to_spec.rb +1 -1
- data/spec/db/database.yml +4 -0
- data/spec/fixtures/test.yml +2 -0
- data/spec/migration_helper.rb +17 -0
- data/spec/spec_helper.rb +4 -0
- metadata +51 -37
- data/lib/cantango/ability/base/callbacks.rb +0 -37
- data/lib/cantango/ability/executor/modes.rb +0 -52
- data/lib/cantango/ability/executor/no_cache_mode.rb +0 -13
- data/spec/cantango/ability/executor/modes_spec.rb +0 -46
- data/spec/cantango/ability/executor/no_cache_mode_spec.rb +0 -29
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cantango-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-12-
|
13
|
+
date: 2011-12-03 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
17
|
-
requirement: &
|
17
|
+
requirement: &70163679813280 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 3.0.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70163679813280
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: cancan
|
28
|
-
requirement: &
|
28
|
+
requirement: &70163679812800 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '1.4'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70163679812800
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: sugar-high
|
39
|
-
requirement: &
|
39
|
+
requirement: &70163679812280 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 0.6.0
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70163679812280
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: sweetloader
|
50
|
-
requirement: &
|
50
|
+
requirement: &70163679811380 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 0.1.5
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70163679811380
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: hashie
|
61
|
-
requirement: &
|
61
|
+
requirement: &70163679810520 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70163679810520
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec-rails
|
72
|
-
requirement: &
|
72
|
+
requirement: &70163679809380 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: 2.6.1
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70163679809380
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: forgery
|
83
|
-
requirement: &
|
83
|
+
requirement: &70163679808280 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: '0.3'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *70163679808280
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: factory_girl
|
94
|
-
requirement: &
|
94
|
+
requirement: &70163679807800 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ! '>='
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: '0'
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *70163679807800
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: sqlite3
|
105
|
-
requirement: &
|
105
|
+
requirement: &70163679807260 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ! '>='
|
@@ -110,10 +110,10 @@ dependencies:
|
|
110
110
|
version: '0'
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *70163679807260
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: rspec
|
116
|
-
requirement: &
|
116
|
+
requirement: &70163679806460 !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
119
119
|
- - ! '>='
|
@@ -121,10 +121,10 @@ dependencies:
|
|
121
121
|
version: 2.6.0
|
122
122
|
type: :development
|
123
123
|
prerelease: false
|
124
|
-
version_requirements: *
|
124
|
+
version_requirements: *70163679806460
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: jeweler
|
127
|
-
requirement: &
|
127
|
+
requirement: &70163679805780 !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
130
130
|
- - ! '>='
|
@@ -132,10 +132,10 @@ dependencies:
|
|
132
132
|
version: 1.6.4
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
|
-
version_requirements: *
|
135
|
+
version_requirements: *70163679805780
|
136
136
|
- !ruby/object:Gem::Dependency
|
137
137
|
name: bundler
|
138
|
-
requirement: &
|
138
|
+
requirement: &70163679805020 !ruby/object:Gem::Requirement
|
139
139
|
none: false
|
140
140
|
requirements:
|
141
141
|
- - ! '>='
|
@@ -143,10 +143,10 @@ dependencies:
|
|
143
143
|
version: 1.1.rc
|
144
144
|
type: :development
|
145
145
|
prerelease: false
|
146
|
-
version_requirements: *
|
146
|
+
version_requirements: *70163679805020
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
148
|
name: rdoc
|
149
|
-
requirement: &
|
149
|
+
requirement: &70163679804300 !ruby/object:Gem::Requirement
|
150
150
|
none: false
|
151
151
|
requirements:
|
152
152
|
- - ! '>='
|
@@ -154,10 +154,10 @@ dependencies:
|
|
154
154
|
version: '0'
|
155
155
|
type: :development
|
156
156
|
prerelease: false
|
157
|
-
version_requirements: *
|
157
|
+
version_requirements: *70163679804300
|
158
158
|
- !ruby/object:Gem::Dependency
|
159
159
|
name: rake
|
160
|
-
requirement: &
|
160
|
+
requirement: &70163679803780 !ruby/object:Gem::Requirement
|
161
161
|
none: false
|
162
162
|
requirements:
|
163
163
|
- - ! '>='
|
@@ -165,7 +165,7 @@ dependencies:
|
|
165
165
|
version: 0.9.2.2
|
166
166
|
type: :development
|
167
167
|
prerelease: false
|
168
|
-
version_requirements: *
|
168
|
+
version_requirements: *70163679803780
|
169
169
|
description: ! 'Define your permission rules as role- or role group specific permits.
|
170
170
|
|
171
171
|
Integrates well with multiple Devise user acounts.
|
@@ -191,17 +191,21 @@ files:
|
|
191
191
|
- cantango-core.gemspec
|
192
192
|
- lib/cantango/ability.rb
|
193
193
|
- lib/cantango/ability/base.rb
|
194
|
-
- lib/cantango/ability/base/callbacks.rb
|
195
194
|
- lib/cantango/ability/cache.rb
|
196
195
|
- lib/cantango/ability/cache/simple_key.rb
|
196
|
+
- lib/cantango/ability/callbacks.rb
|
197
197
|
- lib/cantango/ability/executor.rb
|
198
198
|
- lib/cantango/ability/executor/base.rb
|
199
|
-
- lib/cantango/ability/executor/
|
200
|
-
- lib/cantango/ability/executor/no_cache_mode.rb
|
199
|
+
- lib/cantango/ability/executor/modal.rb
|
201
200
|
- lib/cantango/ability/helper.rb
|
202
201
|
- lib/cantango/ability/helper/account.rb
|
203
202
|
- lib/cantango/ability/helper/engine.rb
|
204
203
|
- lib/cantango/ability/helper/user.rb
|
204
|
+
- lib/cantango/ability/mode.rb
|
205
|
+
- lib/cantango/ability/mode/base.rb
|
206
|
+
- lib/cantango/ability/mode/finder.rb
|
207
|
+
- lib/cantango/ability/mode/no_cache.rb
|
208
|
+
- lib/cantango/ability/rules.rb
|
205
209
|
- lib/cantango/adaptor.rb
|
206
210
|
- lib/cantango/adaptor/active_record.rb
|
207
211
|
- lib/cantango/adaptor/data_mapper.rb
|
@@ -233,15 +237,22 @@ files:
|
|
233
237
|
- lib/generators/cantango/install/templates/cantango.rb
|
234
238
|
- lib/generators/cantango/install/templates/categories.yml
|
235
239
|
- lib/generators/cantango/install/templates/permissions.yml
|
240
|
+
- spec/active_record/001_create_posters.rb
|
241
|
+
- spec/active_record/002_create_users.rb
|
236
242
|
- spec/cantango/ability/base_spec.rb
|
237
243
|
- spec/cantango/ability/cache/simple_key_spec.rb
|
244
|
+
- spec/cantango/ability/callbacks_spec.rb
|
238
245
|
- spec/cantango/ability/executor/base_spec.rb
|
239
246
|
- spec/cantango/ability/executor/custom_spec.rb
|
240
|
-
- spec/cantango/ability/executor/
|
241
|
-
- spec/cantango/ability/
|
247
|
+
- spec/cantango/ability/executor/modal_spec.rb
|
248
|
+
- spec/cantango/ability/executor_spec.rb
|
242
249
|
- spec/cantango/ability/helper/account_spec.rb
|
243
250
|
- spec/cantango/ability/helper/engine_spec.rb
|
244
251
|
- spec/cantango/ability/helper/user_spec.rb
|
252
|
+
- spec/cantango/ability/mode/base_example.rb
|
253
|
+
- spec/cantango/ability/mode/base_spec.rb
|
254
|
+
- spec/cantango/ability/mode/no_cache_spec.rb
|
255
|
+
- spec/cantango/ability/rules_spec.rb
|
245
256
|
- spec/cantango/adaptor/active_record_spec.rb
|
246
257
|
- spec/cantango/adaptor/data_mapper_spec.rb
|
247
258
|
- spec/cantango/adaptor/mongo_mapper_spec.rb
|
@@ -256,13 +267,16 @@ files:
|
|
256
267
|
- spec/cantango/rspec/be_allowed_to_spec.rb
|
257
268
|
- spec/cantango/scope/ability_spec.rb
|
258
269
|
- spec/cantango_spec.rb
|
270
|
+
- spec/db/database.yml
|
259
271
|
- spec/fixtures/models.rb
|
260
272
|
- spec/fixtures/models/account.rb
|
261
273
|
- spec/fixtures/models/admin.rb
|
262
274
|
- spec/fixtures/models/admin_account.rb
|
263
275
|
- spec/fixtures/models/items.rb
|
264
276
|
- spec/fixtures/models/user.rb
|
277
|
+
- spec/fixtures/test.yml
|
265
278
|
- spec/generators/cantango/install_generator_spec.rb
|
279
|
+
- spec/migration_helper.rb
|
266
280
|
- spec/spec_helper.rb
|
267
281
|
homepage: http://github.com/kristianmandrup/cantango
|
268
282
|
licenses:
|
@@ -279,7 +293,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
279
293
|
version: '0'
|
280
294
|
segments:
|
281
295
|
- 0
|
282
|
-
hash:
|
296
|
+
hash: -2968475514432928712
|
283
297
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
284
298
|
none: false
|
285
299
|
requirements:
|
@@ -288,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
288
302
|
version: '0'
|
289
303
|
requirements: []
|
290
304
|
rubyforge_project:
|
291
|
-
rubygems_version: 1.8.
|
305
|
+
rubygems_version: 1.8.6
|
292
306
|
signing_key:
|
293
307
|
specification_version: 3
|
294
308
|
summary: CanCan extension with role oriented permission management and more
|
@@ -1,37 +0,0 @@
|
|
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,52 +0,0 @@
|
|
1
|
-
module CanTango
|
2
|
-
module Ability
|
3
|
-
module Executor
|
4
|
-
class Modes < Base
|
5
|
-
def initialize candidate, options = {}
|
6
|
-
raise "Candidate must be something!" if !candidate
|
7
|
-
@candidate, @options = [candidate, options]
|
8
|
-
calculate_modal_rules.normalize!
|
9
|
-
end
|
10
|
-
|
11
|
-
def rules
|
12
|
-
@rules ||= []
|
13
|
-
end
|
14
|
-
|
15
|
-
def modal_rules mode
|
16
|
-
mode?(mode) ? get_ability(mode).rules : []
|
17
|
-
end
|
18
|
-
|
19
|
-
protected
|
20
|
-
|
21
|
-
def calculate_modal_rules
|
22
|
-
@rules = modes.inject([]) do |result, mode|
|
23
|
-
result = result + modal_rules(mode)
|
24
|
-
result
|
25
|
-
end
|
26
|
-
self
|
27
|
-
end
|
28
|
-
|
29
|
-
def normalize!
|
30
|
-
rules.flatten!
|
31
|
-
rules.compact!
|
32
|
-
end
|
33
|
-
|
34
|
-
def ability_mode_executor_for mode
|
35
|
-
ability_mode_executor_class_for(mode).new candidate, options
|
36
|
-
end
|
37
|
-
|
38
|
-
def ability_mode_executor_class_for mode
|
39
|
-
"CanTango::Ability::Executor::#{mode.to_s.camelize}Mode".constantize
|
40
|
-
end
|
41
|
-
|
42
|
-
def mode? mode
|
43
|
-
modes.include?(mode)
|
44
|
-
end
|
45
|
-
|
46
|
-
def modes
|
47
|
-
@modes ||= options[:modes] || []
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fixtures/models'
|
3
|
-
|
4
|
-
module CanTango::Ability::Executor
|
5
|
-
class CacheMode
|
6
|
-
def permit_rules
|
7
|
-
can :read, Post
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
module CanTango::Ability::Executor
|
13
|
-
class NoCacheMode
|
14
|
-
def permit_rules
|
15
|
-
can :write, Post
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe CanTango::Ability::Executor::Modes do
|
21
|
-
before do
|
22
|
-
@user = User.new 'admin', 'admin@mail.ru'
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'Set execution modes via :modes option'
|
26
|
-
subject do
|
27
|
-
modes_executor = CanTango::Ability::Executor::Modes.new @user
|
28
|
-
modes_executor.modes << :no_cache
|
29
|
-
modes_executor
|
30
|
-
end
|
31
|
-
|
32
|
-
its(:modes) { should include(:no_cache) }
|
33
|
-
its(:non_cached_rules) { should_not be_empty }
|
34
|
-
|
35
|
-
describe 'rules contain only non-cached rules' do
|
36
|
-
specify { subject.rules.size.should == subject.non_cached_rules.size }
|
37
|
-
specify { subject.rules.size.should == 1 }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'Set execution modes via :modes option'
|
42
|
-
subject { @CanTango::Ability::Executor::Modes.new @user, :modes => [:no_cache] }
|
43
|
-
|
44
|
-
its(:modes) { should include(:no_cache) }
|
45
|
-
end
|
46
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fixtures/models'
|
3
|
-
|
4
|
-
module CanTango::Ability::Executor
|
5
|
-
class NoCacheMode
|
6
|
-
def permit_rules
|
7
|
-
can :read, Post
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe CanTango::Ability::Executor::NoCacheMode do
|
13
|
-
context 'no_cached mode only' do
|
14
|
-
before do
|
15
|
-
@user = User.new 'admin', 'admin@mail.ru'
|
16
|
-
@ability = CanTango::Ability::Base.new @user
|
17
|
-
end
|
18
|
-
|
19
|
-
subject { CanTango::Ability::Executor::NoCacheMode.new @ability }
|
20
|
-
|
21
|
-
its(:non_cached_rules) { should be_empty }
|
22
|
-
|
23
|
-
describe 'rules contain only non-cached rules' do
|
24
|
-
specify { subject.rules.size.should == @abil.cached_rules.size }
|
25
|
-
specify { subject.rules.size.should == 1 }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|