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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10f67c0fc1f2251121f9a9bee55f6e0bacd159af
4
- data.tar.gz: f4545cab4d688a0919b95db4d565037fff03b28f
3
+ metadata.gz: c82952010fd76f5d26974f680d0dc06283b16f25
4
+ data.tar.gz: 4e3f57ad48c624f40264fa6371e5a55e943d3ad7
5
5
  SHA512:
6
- metadata.gz: 3d3bfa99d5f81f5ea7796f4e94433cbd8b514e6c6456c90e5c9e1be95c401f69207acb4978014a70f488ae364df4a7fb37f084b5a315de9cbfb6e1aad0c7c7c7
7
- data.tar.gz: 395dfa76bca47f97858af6f27213c4debd9690fc25ec1ac643f3a19fe0f10ccd6793df06995c7a065fdbb79a64cdfbdf63912e95fe2e3e709597a829df5665af
6
+ metadata.gz: 41cd27583e08e15b74cc750407ab8b985f895c674287d7a65ababd8898456fcc99ea8ae2ba59749bc60833ed7e9c29ee2949104b15a007bd4eb14e97e9a86dc9
7
+ data.tar.gz: 86ba561bff04dc96d786ebc70f803221305d693666f257e27ea7ea7771af8cde1d3795483b460eb1c55814f4fb39d2063f1060de4d273568e7dff7c874f4f256
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Bitroleable
2
2
 
3
- Store user's roles in an integer column of database. Have ability to store multi-roles for users.
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, :role, :integer, null: false
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 :role, [:user, :moderator, :admin], multi: true
36
+ roleable :roles, [:user, :moderator, :admin], multi: true
35
37
  end
36
38
  ```
37
39
 
38
- So you can do this:
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 = "Store user's roles in an integer column of database"
11
- spec.description = "Store user's roles in an integer column of database. Have ability to store multi-roles for users."
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
 
@@ -1,3 +1,3 @@
1
1
  module Bitroleable
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
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}"
@@ -20,7 +20,6 @@ module Dummy
20
20
  # config.i18n.default_locale = :de
21
21
 
22
22
  # Do not swallow errors in after_commit/after_rollback callbacks.
23
- config.active_record.raise_in_transactional_callbacks = true
24
23
  end
25
24
  end
26
25
 
@@ -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.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
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.serve_static_files = true
17
- config.static_cache_control = 'public, max-age=3600'
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.2
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: 2015-11-28 00:00:00.000000000 Z
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: Store user's roles in an integer column of database. Have ability to
70
- store multi-roles for users.
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.2.2
155
+ rubygems_version: 2.5.1
156
156
  signing_key:
157
157
  specification_version: 4
158
- summary: Store user's roles in an integer column of database
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