rabarber 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f7d080588bb06feadb9a4f9759415e24828907c520c95bd4174a242820774cf
4
- data.tar.gz: 40a1c865a5fdcfd84980718d61c74cc23ab342a00e1bb933a82ed13b6fbc2a9c
3
+ metadata.gz: 9b3ce45aa7325a095c750691a8633e323a57a987b2c4e4f45902726ce0d30458
4
+ data.tar.gz: 66be6c782c564ef658a405ec94c2ada4b46915820a0b9ac5afcfbf0a5bbcedd8
5
5
  SHA512:
6
- metadata.gz: 0a4f3c2b737c6ad4dff2179aec47835f206b6b750b59a7a3210ba83a905840da679003dad71a9d2b62e07227ad57d861373178cacc2b5ff61431bbbf11aa7023
7
- data.tar.gz: d8a6723c767a24b7653c29b46a2df9ea95a9f2c8994c89e9f2be56d0e00e5024b2b8462aa89a754786322ebf780477fae0db791891e2423ea8d5a28a50866b0a
6
+ metadata.gz: bb12a4ed60e610cb9875243bb87d78ba0e0ab0713507d1967485e16b57fbe7856cbfcf855878b37c75827d02f81fa7baa8cd2f299020bb24dc621fa44aeaf902
7
+ data.tar.gz: 3e65bde49df87b1656eab0b92b8da9cd5fd5975e725911026d8ada08b95eedf912aea4dffb0aa39ba1319979ed4cbb90ff234c66a32b91bbd3c3cda224867e64
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
+ ## 1.0.2
2
+
3
+ - Various enhancements for gem development and release
4
+ - Modify `HasRoles#roles` method to return an array of role names instead of `Rabarber::Role` objects
5
+
1
6
  ## 1.0.1
2
7
 
3
- - Various improvements for gem development
8
+ - Various enhancements for gem development
4
9
 
5
10
  ## 1.0.0
6
11
 
@@ -15,7 +20,7 @@
15
20
 
16
21
  ## 0.1.4
17
22
 
18
- - Remove `role?` method as unnecessary
23
+ - Remove `HasRoles#role?` method as unnecessary
19
24
 
20
25
  ## 0.1.3
21
26
 
data/README.md CHANGED
@@ -136,13 +136,6 @@ To view all the roles assigned to the user, use:
136
136
  ```rb
137
137
  user.roles
138
138
  ```
139
- This will return an array of `Rabarber::Role` objects.
140
-
141
- If you need the list of role names, use:
142
-
143
- ```rb
144
- user.roles.names
145
- ```
146
139
 
147
140
  If you need to list all the role names available in your application, use:
148
141
 
@@ -150,7 +143,9 @@ If you need to list all the role names available in your application, use:
150
143
  Rabarber::Role.names
151
144
  ```
152
145
 
153
- Utilize these methods to manipulate user roles. For example, create a custom UI for managing roles or assign necessary roles during migration or runtime (e.g., when the user is created). You can also write custom authorization policies based on `#has_role?` method (e.g., to scope the data that the user can access). Adapt these methods to fit the requirements of your application.
146
+ `Rabarber::Role` is a model that represents roles within your application. It has a single attribute, `name`, which is validated for both uniqueness and presence. You can treat `Rabarber::Role` as a regular Rails model and use Active Record methods on it if necessary.
147
+
148
+ Utilize the aforementioned methods to manipulate user roles. For example, create a custom UI for managing roles or assign necessary roles during migration or runtime (e.g., when the user is created). You can also write custom authorization policies based on `#has_role?` method (e.g., to scope the data that the user can access). Adapt these methods to fit the requirements of your application.
154
149
 
155
150
  ---
156
151
 
@@ -18,7 +18,7 @@ module Rabarber
18
18
 
19
19
  def verify_access
20
20
  return if Permissions.access_granted?(
21
- send(::Rabarber::Configuration.instance.current_user_method).roles.names, self.class, action_name.to_sym, self
21
+ send(::Rabarber::Configuration.instance.current_user_method).roles, self.class, action_name.to_sym, self
22
22
  )
23
23
 
24
24
  ::Rabarber::Configuration.instance.when_unauthorized.call(self)
@@ -9,15 +9,19 @@ module Rabarber
9
9
 
10
10
  @@included = name
11
11
 
12
- has_and_belongs_to_many :roles, class_name: "Rabarber::Role",
13
- foreign_key: "roleable_id",
14
- join_table: "rabarber_roles_roleables"
12
+ has_and_belongs_to_many :rabarber_roles, class_name: "Rabarber::Role",
13
+ foreign_key: "roleable_id",
14
+ join_table: "rabarber_roles_roleables"
15
+ end
16
+
17
+ def roles
18
+ rabarber_roles.names
15
19
  end
16
20
 
17
21
  def has_role?(*role_names)
18
22
  validate_role_names(role_names)
19
23
 
20
- roles.exists?(name: role_names)
24
+ (roles & role_names).any?
21
25
  end
22
26
 
23
27
  def assign_roles(*role_names, create_new: true)
@@ -25,13 +29,13 @@ module Rabarber
25
29
 
26
30
  create_new_roles(role_names) if create_new
27
31
 
28
- roles << Role.where(name: role_names) - roles
32
+ rabarber_roles << Role.where(name: role_names) - rabarber_roles
29
33
  end
30
34
 
31
35
  def revoke_roles(*role_names)
32
36
  validate_role_names(role_names)
33
37
 
34
- self.roles = roles - Role.where(name: role_names)
38
+ self.rabarber_roles = rabarber_roles - Role.where(name: role_names)
35
39
  end
36
40
 
37
41
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rabarber
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
data/rabarber.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rabarber/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rabarber"
7
+ spec.version = Rabarber::VERSION
8
+ spec.authors = ["enjaku4"]
9
+ spec.email = ["enjaku4@gmail.com"]
10
+
11
+ spec.summary = "Simple authorization library for Ruby on Rails."
12
+ spec.homepage = "https://github.com/enjaku4/rabarber"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 3.0"
15
+
16
+ spec.files = [
17
+ "rabarber.gemspec", "README.md", "CHANGELOG.md", "LICENSE.txt"
18
+ ] + `git ls-files | grep -E '^(lib)'`.split("\n")
19
+
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "rails", ">= 6.1"
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabarber
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - enjaku4
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-31 00:00:00.000000000 Z
11
+ date: 2024-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -31,13 +31,9 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - ".rspec"
35
- - ".rubocop.yml"
36
34
  - CHANGELOG.md
37
- - Gemfile
38
35
  - LICENSE.txt
39
36
  - README.md
40
- - Rakefile
41
37
  - lib/generators/rabarber/roles_generator.rb
42
38
  - lib/generators/rabarber/templates/create_rabarber_roles.rb.erb
43
39
  - lib/rabarber.rb
@@ -50,6 +46,7 @@ files:
50
46
  - lib/rabarber/permissions.rb
51
47
  - lib/rabarber/rule.rb
52
48
  - lib/rabarber/version.rb
49
+ - rabarber.gemspec
53
50
  homepage: https://github.com/enjaku4/rabarber
54
51
  licenses:
55
52
  - MIT
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --format progress
2
- --color
3
- --require spec_helper
4
- --order rand
data/.rubocop.yml DELETED
@@ -1,69 +0,0 @@
1
- require:
2
- - rubocop-rails
3
- - rubocop-rake
4
- - rubocop-rspec
5
-
6
- AllCops:
7
- TargetRubyVersion: 3.0
8
-
9
- Layout/LineLength:
10
- Max: 120
11
-
12
- Metrics/BlockLength:
13
- Enabled: false
14
-
15
- Naming/PredicateName:
16
- Enabled: false
17
-
18
- Rails/ApplicationController:
19
- Exclude:
20
- - spec/support/controllers.rb
21
-
22
- Rails/ApplicationRecord:
23
- Exclude:
24
- - lib/rabarber/models/role.rb
25
- - spec/support/models.rb
26
-
27
- RSpec/ContextWording:
28
- Enabled: false
29
-
30
- RSpec/ExampleLength:
31
- Enabled: false
32
-
33
- RSpec/FilePath:
34
- Enabled: false
35
-
36
- RSpec/MultipleExpectations:
37
- Enabled: false
38
-
39
- RSpec/NamedSubject:
40
- Enabled: false
41
-
42
- RSpec/NestedGroups:
43
- Enabled: false
44
-
45
- Style/ClassVars:
46
- Enabled: false
47
-
48
- Style/Documentation:
49
- Enabled: false
50
-
51
- Style/Lambda:
52
- Enabled: true
53
- EnforcedStyle: literal
54
-
55
- Style/StringLiterals:
56
- Enabled: true
57
- EnforcedStyle: double_quotes
58
-
59
- Style/StringLiteralsInInterpolation:
60
- Enabled: true
61
- EnforcedStyle: double_quotes
62
-
63
- Style/SymbolArray:
64
- Enabled: true
65
- EnforcedStyle: brackets
66
-
67
- Style/WordArray:
68
- Enabled: true
69
- EnforcedStyle: brackets
data/Gemfile DELETED
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gemspec
6
-
7
- ENV["RAILS_VERSION"] ? gem("rails", ENV["RAILS_VERSION"]) : gem("rails", ">= 6.1")
8
-
9
- gem "database_cleaner-active_record", "~> 2.1"
10
- gem "rake", "~> 13.1"
11
- gem "rspec", "~> 3.12"
12
- gem "rspec-rails", "~> 6.1"
13
- gem "rubocop", "~> 1.59"
14
- gem "rubocop-rails", "~> 2.23"
15
- gem "rubocop-rake", "~> 0.6"
16
- gem "rubocop-rspec", "~> 2.25"
17
- gem "sqlite3", "~> 1.7"
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: [:spec, :rubocop]