rabarber 6.0.1 → 6.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
  SHA256:
3
- metadata.gz: 6cb92ea0f4a25ee7dd730aae35b07d16230434393882cd0833d853117e7887e9
4
- data.tar.gz: 3056af62a93df97b88f708dc725e0b54c92cfc198aad225ba80262fcfd36a31a
3
+ metadata.gz: c7481864a3dc409501c34dc66d1f7bfe3399118285fb99cbc6979b17c1b75ff3
4
+ data.tar.gz: ea2c8e12a4a28be3166d4fb60db78e5c5857e838697a5b2308db2486e81d92ad
5
5
  SHA512:
6
- metadata.gz: 1e599ea0709127eeed62dd0aae019f9dee5a73843e08671089e1a84b16e13a2db4ad8f908080b51f3a5a8d2fa82d9a7f21efed638dd6e1054f5c80fdb8b5f423
7
- data.tar.gz: 0b2548c277de1beb990d9ce0321b0989d7358c521e3cb0d20994cf389ea931feb288dc670d7e886c6a1ccff29dc4d7bdd7c1a07885f0ad327f7b94e3cf8d6f82
6
+ metadata.gz: 239a2ba8dc2541688ab09fdbf143d9246e6a725d5ac8adebd253c2ef5d2a7935a4b51d4dffadfb6f490cb6871955b1832c6f24188bfe389abbf22287627652d8
7
+ data.tar.gz: bdf91f9803ec0fd770a7bdb8b0267e63566078a7496b736b0cfdc8a2b7084c73be0836148e0d89e887f8753338fc9efa3a15213f3fa839229b041497349f8908
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## v6.0.3
2
+
3
+ ### Bugs:
4
+
5
+ - Fixed `Rabarber.all_roles` raising `Rabarber::NotFoundError` when a role's context is a class that is not an ActiveRecord model
6
+
7
+ ## v6.0.2
8
+
9
+ ### Bugs:
10
+
11
+ - Fixed Rails commands failing when the configured user model class does not exist yet
12
+
1
13
  ## v6.0.1
2
14
 
3
15
  ### Bugs:
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Rabarber: Simple Role-Based Authorization for Rails
1
+ # Rabarber: Simple Authorization for Rails
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rabarber.svg)](http://badge.fury.io/rb/rabarber)
4
4
  [![Downloads](https://img.shields.io/gem/dt/rabarber.svg)](https://rubygems.org/gems/rabarber)
@@ -409,7 +409,7 @@ end
409
409
 
410
410
  When a context object is deleted from your database, its associated roles become orphaned and ignored by Rabarber.
411
411
 
412
- To clean up orphaned roles, use:
412
+ Ideally, the application should be designed so that this doesn't happen: whenever a context object is deleted, its roles are revoked and deleted as part of the same operation. However, if that wasn't done, you can clean up the orphaned roles as a fallback:
413
413
 
414
414
  ```rb
415
415
  Rabarber.prune
@@ -3,6 +3,8 @@
3
3
  module Rabarber
4
4
  module Core
5
5
  module Roleable
6
+ private
7
+
6
8
  def roleable
7
9
  current_roleable = send(Rabarber::Configuration.current_user_method)
8
10
 
@@ -15,10 +17,6 @@ module Rabarber
15
17
 
16
18
  current_roleable
17
19
  end
18
-
19
- def roleable_roles(context: nil)
20
- roleable.roles(context:)
21
- end
22
20
  end
23
21
  end
24
22
  end
@@ -12,7 +12,9 @@ module Rabarber
12
12
  end
13
13
 
14
14
  def list_all
15
- includes(:context).each_with_object({}) do |role, hash|
15
+ roles = where(context_id: nil).to_a + where.not(context_id: nil).includes(:context).to_a
16
+
17
+ roles.each_with_object({}) do |role, hash|
16
18
  (hash[role.context] ||= []) << role.name.to_sym
17
19
  rescue ActiveRecord::RecordNotFound
18
20
  next
@@ -4,31 +4,18 @@ require "rails/railtie"
4
4
 
5
5
  module Rabarber
6
6
  class Railtie < Rails::Railtie
7
- def self.server_running?
8
- !!defined?(Rails::Server)
9
- end
10
-
11
- def self.table_exists?
12
- ActiveRecord::Base.connection.data_source_exists?("rabarber_roles")
13
- rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished
14
- false
7
+ initializer "rabarber.include_roleable" do
8
+ Rails.autoloaders.each do |autoloader|
9
+ autoloader.on_load do |cpath, klass, _abspath|
10
+ klass.include Rabarber::Roleable if cpath == Rabarber::Configuration.user_model_name
11
+ end
12
+ end
15
13
  end
16
14
 
17
15
  initializer "rabarber.to_prepare" do |app|
18
16
  app.config.to_prepare do
19
- if Rabarber::Railtie.server_running? && Rabarber::Railtie.table_exists?
20
- Rabarber::Role.where.not(context_type: nil).distinct.pluck(:context_type).each do |context_class|
21
- context_class.constantize
22
- rescue NameError => e
23
- raise Rabarber::Error, "Context not found: class `#{e.name}` may have been renamed or deleted"
24
- end
25
- end
26
-
27
17
  Rabarber::Core::Permissions.reset! unless app.config.eager_load
28
18
 
29
- user_model = Rabarber::Configuration.user_model
30
- user_model.include Rabarber::Roleable unless user_model < Rabarber::Roleable
31
-
32
19
  Rabarber::Role.send(:remove_const, :HABTM_Roleables) if Rabarber::Role.const_defined?(:HABTM_Roleables, false)
33
20
  Rabarber::Role.has_and_belongs_to_many :roleables, class_name: Rabarber::Configuration.user_model_name,
34
21
  association_foreign_key: "roleable_id",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rabarber
4
- VERSION = "6.0.1"
4
+ VERSION = "6.0.3"
5
5
  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: 6.0.1
4
+ version: 6.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - enjaku4
8
8
  - trafium
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-07-19 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 4.0.15
101
+ rubygems_version: 4.0.16
102
102
  specification_version: 4
103
103
  summary: Simple role-based authorization library for Ruby on Rails
104
104
  test_files: []