cantango-core 0.1.9.2 → 0.1.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -11,7 +11,6 @@ end
11
11
  group :test do
12
12
  gem 'require_all', '~> 1.2.0'
13
13
 
14
-
15
14
  gem 'cancan', '>= 1.4'
16
15
 
17
16
  # Data
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9.2
1
+ 0.1.9.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cantango-core}
8
- s.version = "0.1.9.2"
8
+ s.version = "0.1.9.3"
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-12-08}
12
+ s.date = %q{2011-12-09}
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.
@@ -98,6 +98,7 @@ Store permissions in yaml file or key-value store}
98
98
  "spec/cantango/adaptor/data_mapper_spec.rb",
99
99
  "spec/cantango/adaptor/mongo_mapper_spec.rb",
100
100
  "spec/cantango/adaptor/mongoid_spec.rb",
101
+ "spec/cantango/adaptor_spec.rb",
101
102
  "spec/cantango/cancan/rule_class_spec.rb",
102
103
  "spec/cantango/cancan/rule_spec.rb",
103
104
  "spec/cantango/core_spec.rb",
@@ -5,21 +5,27 @@ module CanTango
5
5
 
6
6
  # include adaptor depending on which ORM the object inherits from or includes
7
7
  def use_adaptor! base, object
8
- orm_map.each_pair do |orm, const|
8
+ base.class.send :include, adaptor_for(object)
9
+ end
10
+
11
+ def adaptor_for object
12
+ "CanTango::Adaptor::#{orm_for(object).to_s.camelize}".constantize
13
+ end
14
+
15
+ def orm_for object
16
+ matching_orm(object) || :generic
17
+ end
18
+
19
+ def matching_orm object
20
+ orm = orm_map.select do |orm, const|
9
21
  begin
10
- base.class.send :include, get_adapter(object, const.constantize, orm)
22
+ orm_const = const.constantize
23
+ object.kind_of?(orm_const)
11
24
  rescue
12
25
  next
13
26
  end
14
27
  end
15
- end
16
-
17
- def get_adapter object, adaptor_class, orm
18
- object.kind_of?(adaptor_class) ? adaptor_for(orm) : adaptor_for(:generic)
19
- end
20
-
21
- def adaptor_for orm
22
- "#{self.class}::#{orm.to_s.camelize}".constantize
28
+ orm.empty? ? nil : orm.keys.first
23
29
  end
24
30
 
25
31
  def orm_map
@@ -1,6 +1,10 @@
1
1
  module CanTango::Adaptor
2
2
  module ActiveRecord
3
3
  include CanTango::Adaptor::Relational
4
+
5
+ def adaptor_type
6
+ :active_record
7
+ end
4
8
  end
5
9
  end
6
10
 
@@ -1,5 +1,9 @@
1
1
  module CanTango::Adaptor
2
2
  module DataMapper
3
3
  include CanTango::Adaptor::Relational
4
+
5
+ def adaptor_type
6
+ :data_mapper
7
+ end
4
8
  end
5
9
  end
@@ -1,6 +1,5 @@
1
1
  module CanTango::Adaptor
2
2
  module Generic
3
-
4
3
  def attribute_condition attribute, candidate
5
4
  Proc.new { |model| model.send(attribute) == candidate }
6
5
  end
@@ -8,5 +7,9 @@ module CanTango::Adaptor
8
7
  def include_condition attribute, candidate
9
8
  Proc.new { |model| model.send(attribute).include? candidate }
10
9
  end
10
+
11
+ def adaptor_type
12
+ :generic
13
+ end
11
14
  end
12
15
  end
@@ -1,5 +1,9 @@
1
1
  module CanTango::Adaptor
2
2
  module MongoMapper
3
3
  include CanTango::Adaptor::Mongo
4
+
5
+ def adaptor_type
6
+ :mongo_mapper
7
+ end
4
8
  end
5
9
  end
@@ -1,5 +1,9 @@
1
1
  module CanTango::Adaptor
2
2
  module Mongoid
3
3
  include CanTango::Adaptor::Mongo
4
+
5
+ def adaptor_type
6
+ :mongoid
7
+ end
4
8
  end
5
9
  end
@@ -11,7 +11,6 @@ class User < ActiveRecord::Base
11
11
  has_many :posters
12
12
  end
13
13
 
14
-
15
14
  module CanTango::Ability
16
15
  class Base
17
16
  def calculate_rules
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+ require 'fixtures/models'
3
+ require 'migration_helper'
4
+
5
+ class Poster < ActiveRecord::Base
6
+ belongs_to :owner, :class_name => "User", :foreign_key => "user_id"
7
+ end
8
+
9
+ class Adaptation
10
+ include CanTango::Adaptor
11
+ end
12
+
13
+ class GenericClazz
14
+ end
15
+
16
+ class ArClazz
17
+ end
18
+
19
+
20
+ describe CanTango::Adaptor do
21
+ before do
22
+ @post = Post.new
23
+ @poster = Poster.new
24
+ @generic_clazz = GenericClazz
25
+ @ar_class = ArClazz
26
+ end
27
+ subject { Adaptation.new }
28
+
29
+ describe 'matching_orm(obj)' do
30
+ context 'Generic obj' do
31
+ specify { subject.matching_orm(@post).should == nil }
32
+ end
33
+
34
+ context 'Active Record obj' do
35
+ specify { subject.matching_orm(@poster).should == :active_record }
36
+ end
37
+ end
38
+
39
+ describe 'orm_for(obj)' do
40
+ context 'Generic obj' do
41
+ specify { subject.orm_for(@post).should == :generic }
42
+ end
43
+
44
+ context 'Active Record obj' do
45
+ specify { subject.orm_for(@poster).should == :active_record }
46
+ end
47
+ end
48
+
49
+ describe 'adaptor_for(obj)' do
50
+ context 'Generic obj' do
51
+ specify { subject.adaptor_for(@post).should == CanTango::Adaptor::Generic }
52
+ end
53
+
54
+ context 'Active Record obj' do
55
+ specify { subject.adaptor_for(@poster).should == CanTango::Adaptor::ActiveRecord }
56
+ end
57
+ end
58
+
59
+ describe 'use_adaptor! base, object' do
60
+ context 'Generic obj' do
61
+ before do
62
+ subject.use_adaptor!(@generic_clazz, @post)
63
+ end
64
+ specify { @generic_clazz.adaptor_type.should == :generic }
65
+ end
66
+
67
+ context 'Active Record obj' do
68
+ before do
69
+ subject.use_adaptor!(@ar_clazz, @poster)
70
+ end
71
+ specify { @ar_clazz.adaptor_type.should == :active_record }
72
+
73
+ end
74
+ end
75
+
76
+
77
+ # def use_adaptor! base, object
78
+ # base.class.send :include, adaptor_for(object)
79
+ # end
80
+
81
+
82
+ # def use_adaptor! base, object
83
+ # base.class.send :include, adaptor_for(object)
84
+ # end
85
+ #
86
+ # def adaptor_for object
87
+ # "#{self.class}::#{orm_for(object).to_s.camelize}".constantize
88
+ # end
89
+ #
90
+ # def orm_for object
91
+ # matching_orm(object) || :generic
92
+ # end
93
+ #
94
+ # def matching_orm object
95
+
96
+ end
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.9.2
4
+ version: 0.1.9.3
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-08 00:00:00.000000000Z
13
+ date: 2011-12-09 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &70297625071360 !ruby/object:Gem::Requirement
17
+ requirement: &70359830605380 !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: *70297625071360
25
+ version_requirements: *70359830605380
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: cancan
28
- requirement: &70297625070560 !ruby/object:Gem::Requirement
28
+ requirement: &70359830604820 !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: *70297625070560
36
+ version_requirements: *70359830604820
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: sugar-high
39
- requirement: &70297625069680 !ruby/object:Gem::Requirement
39
+ requirement: &70359830604140 !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: *70297625069680
47
+ version_requirements: *70359830604140
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: sweetloader
50
- requirement: &70297625068300 !ruby/object:Gem::Requirement
50
+ requirement: &70359830603220 !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: *70297625068300
58
+ version_requirements: *70359830603220
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: hashie
61
- requirement: &70297625067480 !ruby/object:Gem::Requirement
61
+ requirement: &70359830602040 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '1.2'
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *70297625067480
69
+ version_requirements: *70359830602040
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rspec-rails
72
- requirement: &70297625066020 !ruby/object:Gem::Requirement
72
+ requirement: &70359830600980 !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: *70297625066020
80
+ version_requirements: *70359830600980
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: forgery
83
- requirement: &70297625063380 !ruby/object:Gem::Requirement
83
+ requirement: &70359830599920 !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: *70297625063380
91
+ version_requirements: *70359830599920
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: factory_girl
94
- requirement: &70297625061920 !ruby/object:Gem::Requirement
94
+ requirement: &70359830599120 !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: *70297625061920
102
+ version_requirements: *70359830599120
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: sqlite3
105
- requirement: &70297625046360 !ruby/object:Gem::Requirement
105
+ requirement: &70359830598540 !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: *70297625046360
113
+ version_requirements: *70359830598540
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: rspec
116
- requirement: &70297625045440 !ruby/object:Gem::Requirement
116
+ requirement: &70359830597980 !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: *70297625045440
124
+ version_requirements: *70359830597980
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: jeweler
127
- requirement: &70297625044600 !ruby/object:Gem::Requirement
127
+ requirement: &70359830597480 !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: *70297625044600
135
+ version_requirements: *70359830597480
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: bundler
138
- requirement: &70297625043700 !ruby/object:Gem::Requirement
138
+ requirement: &70359830596960 !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: *70297625043700
146
+ version_requirements: *70359830596960
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: rdoc
149
- requirement: &70297625042260 !ruby/object:Gem::Requirement
149
+ requirement: &70359830596380 !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: *70297625042260
157
+ version_requirements: *70359830596380
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: rake
160
- requirement: &70297625040440 !ruby/object:Gem::Requirement
160
+ requirement: &70359830595900 !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: *70297625040440
168
+ version_requirements: *70359830595900
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.
@@ -258,6 +258,7 @@ files:
258
258
  - spec/cantango/adaptor/data_mapper_spec.rb
259
259
  - spec/cantango/adaptor/mongo_mapper_spec.rb
260
260
  - spec/cantango/adaptor/mongoid_spec.rb
261
+ - spec/cantango/adaptor_spec.rb
261
262
  - spec/cantango/cancan/rule_class_spec.rb
262
263
  - spec/cantango/cancan/rule_spec.rb
263
264
  - spec/cantango/core_spec.rb
@@ -295,7 +296,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
295
296
  version: '0'
296
297
  segments:
297
298
  - 0
298
- hash: 3380786207970925537
299
+ hash: -1538863595410503402
299
300
  required_rubygems_version: !ruby/object:Gem::Requirement
300
301
  none: false
301
302
  requirements: