bitroleable 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/README.md +16 -5
- data/bitroleable.gemspec +2 -2
- data/lib/bitroleable/version.rb +1 -1
- data/lib/bitroleable.rb +8 -0
- data/spec/dummy/config/application.rb +0 -1
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/environments/test.rb +2 -2
- data/spec/models/bitroleable_spec.rb +11 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c82952010fd76f5d26974f680d0dc06283b16f25
|
4
|
+
data.tar.gz: 4e3f57ad48c624f40264fa6371e5a55e943d3ad7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41cd27583e08e15b74cc750407ab8b985f895c674287d7a65ababd8898456fcc99ea8ae2ba59749bc60833ed7e9c29ee2949104b15a007bd4eb14e97e9a86dc9
|
7
|
+
data.tar.gz: 86ba561bff04dc96d786ebc70f803221305d693666f257e27ea7ea7771af8cde1d3795483b460eb1c55814f4fb39d2063f1060de4d273568e7dff7c874f4f256
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Bitroleable
|
2
2
|
|
3
|
-
|
3
|
+
Manage user roles. Each user's role is stored as a bit in an integer
|
4
|
+
column of database. Also provides user ability to have one role and
|
5
|
+
some roles.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -23,7 +25,7 @@ Or install it yourself as:
|
|
23
25
|
Add a column which will store role/roles as integer:
|
24
26
|
|
25
27
|
```ruby
|
26
|
-
add_column :user, :
|
28
|
+
add_column :user, :roles, :integer, null: false
|
27
29
|
```
|
28
30
|
|
29
31
|
And then tell a model that you use this gem functionality:
|
@@ -31,15 +33,21 @@ And then tell a model that you use this gem functionality:
|
|
31
33
|
```ruby
|
32
34
|
# app/models/user.rb
|
33
35
|
class User < ActiveRecord::Base
|
34
|
-
roleable :
|
36
|
+
roleable :roles, [:user, :moderator, :admin], multi: true
|
35
37
|
end
|
36
38
|
```
|
37
39
|
|
38
|
-
|
40
|
+
### Options
|
41
|
+
|
42
|
+
For now it has only one option:
|
43
|
+
|
44
|
+
- `multi` (boolean) - when it equals `true` an entity could have many roles, otherwise only one role
|
45
|
+
|
46
|
+
### Example
|
39
47
|
|
40
48
|
```ruby
|
41
49
|
user = User.first
|
42
|
-
user.admin!
|
50
|
+
user.admin! # => user becomes an admin
|
43
51
|
user.admin? # => true
|
44
52
|
user.user? # => false
|
45
53
|
user.role # => [:admin]
|
@@ -50,6 +58,9 @@ user.save!
|
|
50
58
|
User.where_role(:admin).count # => 0
|
51
59
|
User.where_role(:user).count # => 1
|
52
60
|
User.where_role(:moderator).count # => 1
|
61
|
+
User.roles_list # => [:user, :moderator, :admin]
|
62
|
+
User.role?(:user) # => true
|
63
|
+
User.role?(:fake) # => false
|
53
64
|
```
|
54
65
|
|
55
66
|
## Contributing
|
data/bitroleable.gemspec
CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = Bitroleable::VERSION
|
8
8
|
spec.authors = ['Eugene Kondratiuk']
|
9
9
|
spec.email = ['ekondr@gmail.com']
|
10
|
-
spec.summary = "
|
11
|
-
spec.description = "
|
10
|
+
spec.summary = "Manage user roles. Each user's role is stored as a bit in an integer column of database."
|
11
|
+
spec.description = "Manage user roles. Each user's role is stored as a bit in an integer column of database. Also provides user ability to have one role and some roles."
|
12
12
|
spec.homepage = ''
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
data/lib/bitroleable/version.rb
CHANGED
data/lib/bitroleable.rb
CHANGED
@@ -70,6 +70,14 @@ module Bitroleable
|
|
70
70
|
2**index
|
71
71
|
end
|
72
72
|
|
73
|
+
define_singleton_method :roles_list do
|
74
|
+
roles_list
|
75
|
+
end
|
76
|
+
|
77
|
+
define_singleton_method :role? do |role|
|
78
|
+
roles_list.include?(role.to_sym)
|
79
|
+
end
|
80
|
+
|
73
81
|
define_singleton_method :where_role do |*roles|
|
74
82
|
roles = roles.flatten.compact.map(&:to_sym)
|
75
83
|
tbl_column = "#{self.table_name}.#{column}"
|
@@ -22,7 +22,7 @@ Rails.application.configure do
|
|
22
22
|
|
23
23
|
# Disable serving static files from the `/public` folder by default since
|
24
24
|
# Apache or NGINX already handles this.
|
25
|
-
config.
|
25
|
+
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
26
26
|
|
27
27
|
# Compress JavaScripts and CSS.
|
28
28
|
config.assets.js_compressor = :uglifier
|
@@ -13,8 +13,8 @@ Rails.application.configure do
|
|
13
13
|
config.eager_load = false
|
14
14
|
|
15
15
|
# Configure static file server for tests with Cache-Control for performance.
|
16
|
-
config.
|
17
|
-
config.
|
16
|
+
config.public_file_server.enabled = true
|
17
|
+
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
|
18
18
|
|
19
19
|
# Show full error reports and disable caching.
|
20
20
|
config.consider_all_requests_local = true
|
@@ -16,6 +16,17 @@ RSpec.describe Bitroleable, type: :model do
|
|
16
16
|
expect(User.where_role(:moderator).count).to eq 0
|
17
17
|
end
|
18
18
|
|
19
|
+
it 'should have a list of roles' do
|
20
|
+
expect(User.roles_list).to eq [:user, :moderator, :admin]
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should have ability to check roles' do
|
24
|
+
expect(User.role?(:user)).to eq true
|
25
|
+
expect(User.role?(:moderator)).to eq true
|
26
|
+
expect(User.role?(:admin)).to eq true
|
27
|
+
expect(User.role?(:guest)).to eq false
|
28
|
+
end
|
29
|
+
|
19
30
|
context 'when a role is changed' do
|
20
31
|
before { user.moderator! }
|
21
32
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitroleable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Kondratiuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -66,8 +66,8 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
70
|
-
|
69
|
+
description: Manage user roles. Each user's role is stored as a bit in an integer
|
70
|
+
column of database. Also provides user ability to have one role and some roles.
|
71
71
|
email:
|
72
72
|
- ekondr@gmail.com
|
73
73
|
executables: []
|
@@ -152,10 +152,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|
154
154
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.5.1
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
|
-
summary:
|
158
|
+
summary: Manage user roles. Each user's role is stored as a bit in an integer column
|
159
|
+
of database.
|
159
160
|
test_files:
|
160
161
|
- spec/dummy/README.rdoc
|
161
162
|
- spec/dummy/Rakefile
|