rollable 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,6 +45,8 @@ h2. Features
45
45
 
46
46
  h2. Usage
47
47
 
48
+ We'll call the model that can have roles users, for the sake of laziness.
49
+
48
50
  Rollable provides helpers based on role names to check whether a user has a role on an object:
49
51
 
50
52
  bq. user.is_owner_of?(horse) # => true
@@ -53,10 +55,22 @@ You can also request all possible roles
53
55
 
54
56
  bq. User.role_names
55
57
 
56
- Lastly, if you use nil roles, you can also do
58
+ You can set roles easily by using the helper
59
+
60
+ bq. user.is_owner(horse)
61
+
62
+ If you use nil roles, you can also do
57
63
 
58
64
  bq. user.is_admin?
59
65
 
66
+ Since 0.0.2 you can also do
67
+
68
+ bq. target_model.has_admin?
69
+
70
+ And, to get all users with that role
71
+
72
+ bq. target_model.get_admins
73
+
60
74
  h2. Limitations
61
75
 
62
76
  * Its the first release, don't whine.
@@ -25,13 +25,29 @@ module Rollable
25
25
  set_target_model_helpers
26
26
  set_relations_on_rollables
27
27
  set_role_validations
28
+ set_role_setter_helpers
28
29
  end
29
30
 
30
31
  private
31
32
 
33
+ def set_role_setter_helpers
34
+ rollables = @rollables
35
+ @role_names.each do |name|
36
+ define_method("is_#{name}") do |object|
37
+ if rollables.include?(object.class.to_s)
38
+ self.roles.create!(:rollable => object, :name => name)
39
+ else
40
+ false
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+
32
47
  # DISCLAIMER: Headache and on the airport, hush.
33
48
  # Helpers for target models like has_owner? and get_owners
34
49
  def set_target_model_helpers
50
+ other = self
35
51
  @rollables.select { |r| r.is_a?(String) }.each do |model|
36
52
  model = model.constantize
37
53
  @role_names.each do |role_name|
@@ -42,7 +58,7 @@ module Rollable
42
58
 
43
59
  # TODO: get_#{role_name} doesn't sound very rubyish
44
60
  define_method("get_#{role_name.pluralize}") do
45
- self.roles.where("name = ? ", role_name).collect(&:user)
61
+ self.roles.where("name = ? ", role_name).collect { |r| r.send(other.to_s.downcase) }
46
62
  end
47
63
  end
48
64
  end
@@ -1,3 +1,3 @@
1
1
  module Rollable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -18,7 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
- s.add_dependency "rails", ">= 3.0.0"
22
- s.add_dependency "rspec", "> 2"
21
+ s.add_dependency "rails", "~> 3.0.6"
22
+ s.add_dependency "rspec", "~> 2.6"
23
+ s.add_dependency "rake", "~> 0.8.7"
23
24
  s.add_dependency "rspec-rails"
24
25
  end
@@ -1,6 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'rails', '3.0.7'
4
+ gem 'rake', '~> 0.8.7'
4
5
 
5
6
  # Bundle edge Rails instead:
6
7
  # gem 'rails', :git => 'git://github.com/rails/rails.git'
@@ -28,5 +29,5 @@ gem 'rollable', :path => '../../'
28
29
  # put test-only gems in this group so their generators
29
30
  # and rake tasks are available in development mode:
30
31
  group :development, :test do
31
- gem 'rspec-rails'
32
+ gem 'rspec-rails', '~> 2.6.0'
32
33
  end
@@ -2,6 +2,19 @@ require 'spec_helper'
2
2
 
3
3
  describe User do
4
4
  context "Rollable helpers" do
5
+ it "should respond to setters" do
6
+ @user = User.create
7
+ @user.should respond_to(:is_owner)
8
+ @user.should respond_to(:is_rider)
9
+ end
10
+
11
+ it "should have working setters" do
12
+ @user = User.create
13
+ @horse = Horse.create
14
+ @user.is_owner(@horse)
15
+ @user.is_owner_of?(@horse).should be_true
16
+ end
17
+
5
18
  it "should respond to helper methods" do
6
19
  @user = User.new
7
20
  @user.should respond_to(:is_owner_of?)
metadata CHANGED
@@ -1,60 +1,67 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rollable
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
4
5
  prerelease:
5
- version: 0.0.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Timon Vonk
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-05-05 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2011-06-01 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: rails
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &85659420 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 3.0.0
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.6
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
23
+ prerelease: false
24
+ version_requirements: *85659420
25
+ - !ruby/object:Gem::Dependency
27
26
  name: rspec
27
+ requirement: &85659170 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.6'
33
+ type: :runtime
28
34
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ version_requirements: *85659170
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &85658940 !ruby/object:Gem::Requirement
30
39
  none: false
31
- requirements:
32
- - - ">"
33
- - !ruby/object:Gem::Version
34
- version: "2"
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.8.7
35
44
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: rspec-rails
39
45
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
46
+ version_requirements: *85658940
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec-rails
49
+ requirement: &85658750 !ruby/object:Gem::Requirement
41
50
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
46
55
  type: :runtime
47
- version_requirements: *id003
56
+ prerelease: false
57
+ version_requirements: *85658750
48
58
  description: This gem adds agnostic roles for authorization to Rails.
49
- email:
59
+ email:
50
60
  - mail@timonv.nl
51
61
  executables: []
52
-
53
62
  extensions: []
54
-
55
63
  extra_rdoc_files: []
56
-
57
- files:
64
+ files:
58
65
  - .gitignore
59
66
  - Gemfile
60
67
  - LICENCE
@@ -129,30 +136,85 @@ files:
129
136
  - spec/spec_helper.rb
130
137
  homepage: http://www.timonv.nl
131
138
  licenses: []
132
-
133
139
  post_install_message:
134
140
  rdoc_options: []
135
-
136
- require_paths:
141
+ require_paths:
137
142
  - lib
138
- required_ruby_version: !ruby/object:Gem::Requirement
143
+ required_ruby_version: !ruby/object:Gem::Requirement
139
144
  none: false
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- version: "0"
144
- required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
150
  none: false
146
- requirements:
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- version: "0"
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
150
155
  requirements: []
151
-
152
156
  rubyforge_project: rollable
153
- rubygems_version: 1.7.2
157
+ rubygems_version: 1.8.3
154
158
  signing_key:
155
159
  specification_version: 3
156
160
  summary: Agnostic roles for rails
157
- test_files: []
158
-
161
+ test_files:
162
+ - spec/rollable_test/.gitignore
163
+ - spec/rollable_test/.rspec
164
+ - spec/rollable_test/Gemfile
165
+ - spec/rollable_test/README
166
+ - spec/rollable_test/Rakefile
167
+ - spec/rollable_test/app/controllers/application_controller.rb
168
+ - spec/rollable_test/app/helpers/application_helper.rb
169
+ - spec/rollable_test/app/models/horse.rb
170
+ - spec/rollable_test/app/models/pig.rb
171
+ - spec/rollable_test/app/models/role.rb
172
+ - spec/rollable_test/app/models/user.rb
173
+ - spec/rollable_test/app/views/layouts/application.html.erb
174
+ - spec/rollable_test/config.ru
175
+ - spec/rollable_test/config/application.rb
176
+ - spec/rollable_test/config/boot.rb
177
+ - spec/rollable_test/config/database.yml
178
+ - spec/rollable_test/config/environment.rb
179
+ - spec/rollable_test/config/environments/development.rb
180
+ - spec/rollable_test/config/environments/production.rb
181
+ - spec/rollable_test/config/environments/test.rb
182
+ - spec/rollable_test/config/initializers/backtrace_silencers.rb
183
+ - spec/rollable_test/config/initializers/inflections.rb
184
+ - spec/rollable_test/config/initializers/mime_types.rb
185
+ - spec/rollable_test/config/initializers/secret_token.rb
186
+ - spec/rollable_test/config/initializers/session_store.rb
187
+ - spec/rollable_test/config/locales/en.yml
188
+ - spec/rollable_test/config/routes.rb
189
+ - spec/rollable_test/db/migrate/20110421101457_create_users.rb
190
+ - spec/rollable_test/db/migrate/20110421101514_create_horses.rb
191
+ - spec/rollable_test/db/migrate/20110421101523_create_pigs.rb
192
+ - spec/rollable_test/db/migrate/20110423152854_create_roles.rb
193
+ - spec/rollable_test/db/schema.rb
194
+ - spec/rollable_test/db/seeds.rb
195
+ - spec/rollable_test/doc/README_FOR_APP
196
+ - spec/rollable_test/lib/tasks/.gitkeep
197
+ - spec/rollable_test/public/404.html
198
+ - spec/rollable_test/public/422.html
199
+ - spec/rollable_test/public/500.html
200
+ - spec/rollable_test/public/favicon.ico
201
+ - spec/rollable_test/public/images/rails.png
202
+ - spec/rollable_test/public/index.html
203
+ - spec/rollable_test/public/javascripts/application.js
204
+ - spec/rollable_test/public/javascripts/controls.js
205
+ - spec/rollable_test/public/javascripts/dragdrop.js
206
+ - spec/rollable_test/public/javascripts/effects.js
207
+ - spec/rollable_test/public/javascripts/prototype.js
208
+ - spec/rollable_test/public/javascripts/rails.js
209
+ - spec/rollable_test/public/robots.txt
210
+ - spec/rollable_test/public/stylesheets/.gitkeep
211
+ - spec/rollable_test/script/rails
212
+ - spec/rollable_test/spec/models/horse_spec.rb
213
+ - spec/rollable_test/spec/models/pig_spec.rb
214
+ - spec/rollable_test/spec/models/role_spec.rb
215
+ - spec/rollable_test/spec/models/user_spec.rb
216
+ - spec/rollable_test/spec/spec_helper.rb
217
+ - spec/rollable_test/test/performance/browsing_test.rb
218
+ - spec/rollable_test/test/test_helper.rb
219
+ - spec/rollable_test/vendor/plugins/.gitkeep
220
+ - spec/spec_helper.rb