role_fu 0.3.0 → 0.3.1

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: d75b379be1f3096ca3580d3b5f545c7e10e96a76ade4e1ea8ddf9df11272cf61
4
- data.tar.gz: 9dda6cef944474db4c9fa70979f0a633a3ad90f51bee73faa6cc7ed2e13bfa68
3
+ metadata.gz: b2b6f0598619d72c54eff632b24395808c2e830c1742ae072e5c977ae183f31e
4
+ data.tar.gz: 90b6b655d0858fe2876a530055bc5a4bb27e6f0552b1ad2a4dba4fbc8fedb0e7
5
5
  SHA512:
6
- metadata.gz: 51e073987c36ffd2c6faa06256362a75f79f1a83931fe2bc82e5f4d6750c4a355df4324c3f33dc1dcbe298d3d060b787b6d819da1b693f63edb9d4ed4dc008c5
7
- data.tar.gz: 9e1b6a068bce303db00d70f538a311321fbc2ea1d1032b1522b028d0cf71835c7107589b3f194b48a0c242ba9afab49755a1213ab4a6ce2ba195a06fef8f9a10
6
+ metadata.gz: 46c110643a2838ce274b0041f27c2c47b37a279265e96114f2e4cacd1f7c0964e143575ed171fc4d416c998718392dcd103c0d97d0003330506f240c826fb019
7
+ data.tar.gz: cae97d08a68d4db3700c3801d464ea4369029239eeb3181461043c367cba0f967275a38a80309503a6a994095432530a3204dd257acfa1fff48c6947fd768831
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.1] - 2026-02-06
4
+
5
+ ### Improved
6
+
7
+ - **Generator Flexibility**: `role_fu` generator now supports 0, 1, or 2 arguments for easier setup (e.g., `rails g role_fu Group Account`).
8
+ - **Documentation**: Enhanced CLI help output for all generators, placing usage examples and descriptions prominently above options.
9
+ - **Audit & Ability Generators**: Explicitly documented the `NAME` argument in help banners.
10
+
3
11
  ## [0.3.0] - 2026-02-03
4
12
 
5
13
  ### BREAKING CHANGES
data/README.md CHANGED
@@ -2,13 +2,16 @@
2
2
 
3
3
  RoleFu is a modern, explicit role management gem for Ruby on Rails. It is designed as a cleaner, more performant alternative to legacy role gems, providing full control over role assignments and granular permissions.
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/role_fu.svg)](https://badge.fury.io/rb/role_fu)
6
+ [![Build Status](https://github.com/alec-c4/role_fu/actions/workflows/main.yml/badge.svg)](https://github.com/alec-c4/role_fu/actions)
7
+
5
8
  ## Why RoleFu?
6
9
 
7
10
  - **Explicit Models**: Uses an explicit `RoleAssignment` join model instead of hidden tables, making it easy to add metadata or audit trails.
8
11
  - **N+1 Prevention**: Built-in support for `has_cached_role?` and optimized scopes.
9
12
  - **Strict by Default**: Resource-specific checks are strict, ensuring global roles don't accidentally leak permissions unless configured otherwise.
10
13
  - **Advanced Features**: Supports temporal (expiring) roles, metadata, audit logging, and granular abilities.
11
- - **Modern Infrastructure**: Fully compatible with Rails 7.0 through 8.1, includes Lefthook and Appraisal support.
14
+ - **Modern Infrastructure**: Fully compatible with Rails 7.2 through 8.1, includes Lefthook and Appraisal support.
12
15
 
13
16
  ## Installation
14
17
 
@@ -27,17 +30,33 @@ bundle install
27
30
  ### Setup
28
31
 
29
32
  1. **Install Configuration:**
33
+
30
34
  ```bash
31
35
  rails generate role_fu:install
32
36
  ```
33
37
 
34
38
  2. **Generate Models:**
35
- Default names are `Role` and `RoleAssignment`, linked to the `User` model.
36
- ```bash
37
- rails generate role_fu Role User
38
- ```
39
+
40
+ You can generate the role models with flexible arguments:
41
+
42
+ * **Default (Role & User):**
43
+ ```bash
44
+ rails generate role_fu
45
+ # Generates 'Role' and 'RoleAssignment', linked to 'User'
46
+ ```
47
+ * **Custom Role Name:**
48
+ ```bash
49
+ rails generate role_fu Group
50
+ # Generates 'Group' and 'GroupAssignment', linked to 'User'
51
+ ```
52
+ * **Custom Role & User Names:**
53
+ ```bash
54
+ rails generate role_fu Group Account
55
+ # Generates 'Group' and 'GroupAssignment', linked to 'Account'
56
+ ```
39
57
 
40
58
  3. **Run Migrations:**
59
+
41
60
  ```bash
42
61
  rails db:migrate
43
62
  ```
@@ -95,6 +114,7 @@ User.with_all_roles(:admin, :manager)
95
114
  ### Advanced Features
96
115
 
97
116
  #### 1. Temporal Roles (Expiration)
117
+
98
118
  Roles can be assigned with an expiration time. They are automatically filtered out from queries once expired.
99
119
 
100
120
  ```ruby
@@ -108,6 +128,7 @@ user.grant(:manager, org, expires_at: 1.week.from_now)
108
128
  ```
109
129
 
110
130
  #### 2. Metadata
131
+
111
132
  Attach arbitrary metadata to a role assignment.
112
133
 
113
134
  ```ruby
@@ -115,16 +136,21 @@ user.grant(:manager, org, meta: { assigned_by: current_user.id, reason: "Project
115
136
  ```
116
137
 
117
138
  #### 3. Audit Log
139
+
118
140
  Track every grant, revoke, and update (e.g., expiration extensions).
119
141
 
120
142
  **Setup:**
143
+
121
144
  ```bash
122
145
  rails generate role_fu:audit
146
+ # OR with a custom name:
147
+ # rails generate role_fu:audit MyAudit
123
148
  rails db:migrate
124
149
  ```
125
150
 
126
151
  **Usage:**
127
152
  Wrap changes in `with_actor` to capture the responsible user:
153
+
128
154
  ```ruby
129
155
  RoleFu.with_actor(current_user) do
130
156
  user.grant(:manager, org)
@@ -136,15 +162,20 @@ RoleAssignmentAudit.where(user: user).last
136
162
  ```
137
163
 
138
164
  #### 4. Role Abilities (Permissions)
165
+
139
166
  Attach granular permissions to roles.
140
167
 
141
168
  **Setup:**
169
+
142
170
  ```bash
143
171
  rails generate role_fu:abilities
172
+ # OR with a custom name:
173
+ # rails generate role_fu:abilities MyPermission
144
174
  rails db:migrate
145
175
  ```
146
176
 
147
177
  **Usage:**
178
+
148
179
  ```ruby
149
180
  # Setup permissions
150
181
  manager_role = Role.find_by(name: "manager")
@@ -159,6 +190,7 @@ user.role_fu_can?("posts.edit") # => true
159
190
  ### Adapters (Pundit & CanCanCan)
160
191
 
161
192
  #### CanCanCan
193
+
162
194
  ```ruby
163
195
  class Ability
164
196
  include CanCan::Ability
@@ -171,12 +203,14 @@ end
171
203
  ```
172
204
 
173
205
  #### Pundit
206
+
174
207
  ```ruby
175
208
  class ApplicationPolicy
176
209
  include RoleFu::Adapters::Pundit
177
210
  end
178
211
  ```
179
- *`PostPolicy#update?` will automatically check `user.role_fu_can?('posts.update')`.*
212
+
213
+ _`PostPolicy#update?` will automatically check `user.role_fu_can?('posts.update')`._
180
214
 
181
215
  ---
182
216
 
@@ -217,7 +251,7 @@ Customize your model names in `config/initializers/role_fu.rb`:
217
251
  RoleFu.configure do |config|
218
252
  config.user_class_name = "Account"
219
253
  config.role_class_name = "Group"
220
-
254
+
221
255
  # Enable Rolify-style permissive checks (Global roles override resource checks)
222
256
  config.global_roles_override = true
223
257
  end
@@ -244,11 +278,13 @@ User.not_in_group(:admin) # Alias for without_group/without_role
244
278
 
245
279
  1. **Code Changes**: Replace `rolify` with `include RoleFu::Roleable` and `resourcify` with `include RoleFu::Resourceable`.
246
280
  2. **Data Migration**:
281
+
247
282
  ```sql
248
283
  INSERT INTO role_assignments (user_id, role_id, created_at, updated_at)
249
284
  SELECT user_id, role_id, NOW(), NOW()
250
285
  FROM users_roles;
251
286
  ```
287
+
252
288
  3. **Behavior**: Set `config.global_roles_override = true` if you rely on global roles satisfying resource checks.
253
289
 
254
290
  ## License
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- role_fu (0.3.0)
4
+ role_fu (0.3.1)
5
5
  activerecord (>= 7.2)
6
6
 
7
7
  GEM
@@ -389,7 +389,7 @@ CHECKSUMS
389
389
  rdoc (7.1.0) sha256=494899df0706c178596ca6e1d50f1b7eb285a9b2aae715be5abd742734f17363
390
390
  regexp_parser (2.11.3) sha256=ca13f381a173b7a93450e53459075c9b76a10433caadcb2f1180f2c741fc55a4
391
391
  reline (0.6.3) sha256=1198b04973565b36ec0f11542ab3f5cfeeec34823f4e54cebde90968092b1835
392
- role_fu (0.3.0)
392
+ role_fu (0.3.1)
393
393
  rspec (3.13.2) sha256=206284a08ad798e61f86d7ca3e376718d52c0bc944626b2349266f239f820587
394
394
  rspec-core (3.13.6) sha256=a8823c6411667b60a8bca135364351dda34cd55e44ff94c4be4633b37d828b2d
395
395
  rspec-expectations (3.13.5) sha256=33a4d3a1d95060aea4c94e9f237030a8f9eae5615e9bd85718fe3a09e4b58836
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- role_fu (0.3.0)
4
+ role_fu (0.3.1)
5
5
  activerecord (>= 7.2)
6
6
 
7
7
  GEM
@@ -385,7 +385,7 @@ CHECKSUMS
385
385
  rdoc (7.1.0) sha256=494899df0706c178596ca6e1d50f1b7eb285a9b2aae715be5abd742734f17363
386
386
  regexp_parser (2.11.3) sha256=ca13f381a173b7a93450e53459075c9b76a10433caadcb2f1180f2c741fc55a4
387
387
  reline (0.6.3) sha256=1198b04973565b36ec0f11542ab3f5cfeeec34823f4e54cebde90968092b1835
388
- role_fu (0.3.0)
388
+ role_fu (0.3.1)
389
389
  rspec (3.13.2) sha256=206284a08ad798e61f86d7ca3e376718d52c0bc944626b2349266f239f820587
390
390
  rspec-core (3.13.6) sha256=a8823c6411667b60a8bca135364351dda34cd55e44ff94c4be4633b37d828b2d
391
391
  rspec-expectations (3.13.5) sha256=33a4d3a1d95060aea4c94e9f237030a8f9eae5615e9bd85718fe3a09e4b58836
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- role_fu (0.3.0)
4
+ role_fu (0.3.1)
5
5
  activerecord (>= 7.2)
6
6
 
7
7
  GEM
@@ -387,7 +387,7 @@ CHECKSUMS
387
387
  rdoc (7.1.0) sha256=494899df0706c178596ca6e1d50f1b7eb285a9b2aae715be5abd742734f17363
388
388
  regexp_parser (2.11.3) sha256=ca13f381a173b7a93450e53459075c9b76a10433caadcb2f1180f2c741fc55a4
389
389
  reline (0.6.3) sha256=1198b04973565b36ec0f11542ab3f5cfeeec34823f4e54cebde90968092b1835
390
- role_fu (0.3.0)
390
+ role_fu (0.3.1)
391
391
  rspec (3.13.2) sha256=206284a08ad798e61f86d7ca3e376718d52c0bc944626b2349266f239f820587
392
392
  rspec-core (3.13.6) sha256=a8823c6411667b60a8bca135364351dda34cd55e44ff94c4be4633b37d828b2d
393
393
  rspec-expectations (3.13.5) sha256=33a4d3a1d95060aea4c94e9f237030a8f9eae5615e9bd85718fe3a09e4b58836
@@ -7,11 +7,21 @@ module RoleFu
7
7
  class AbilitiesGenerator < ActiveRecord::Generators::Base
8
8
  source_root File.expand_path("templates", __dir__)
9
9
 
10
+ argument :name, type: :string, default: "abilities"
11
+
12
+ def self.banner
13
+ "bin/rails generate role_fu:abilities [NAME] [options]\n\n" \
14
+ "Generates the permission model and migration.\n" \
15
+ " NAME is the name of the permission model (default: 'abilities')."
16
+ end
17
+
18
+ desc ""
19
+
10
20
  def generate_permission_model
11
21
  template "permission.rb.erb", "app/models/permission.rb"
12
22
  end
13
23
 
14
- def create_migration
24
+ def create_abilities_migration
15
25
  migration_template "abilities_migration.rb.erb", "db/migrate/role_fu_create_permissions.rb", migration_version: migration_version
16
26
  end
17
27
 
@@ -7,7 +7,17 @@ module RoleFu
7
7
  class AuditGenerator < ActiveRecord::Generators::Base
8
8
  source_root File.expand_path("templates", __dir__)
9
9
 
10
- def create_migration
10
+ argument :name, type: :string, default: "audit"
11
+
12
+ def self.banner
13
+ "bin/rails generate role_fu:audit [NAME] [options]\n\n" \
14
+ "Generates the audit model and migration.\n" \
15
+ " NAME is the name of the audit model (default: 'audit')."
16
+ end
17
+
18
+ desc "" # Empty desc to avoid duplication at the bottom
19
+
20
+ def create_audit_migration
11
21
  migration_template "audit_migration.rb.erb", "db/migrate/role_fu_create_audits.rb", migration_version: migration_version
12
22
  end
13
23
 
@@ -7,8 +7,22 @@ module RoleFu
7
7
  class RoleFuGenerator < ActiveRecord::Generators::Base
8
8
  source_root File.expand_path("templates", __dir__)
9
9
 
10
+ # Override the default 'name' argument to be optional with default "Role"
11
+ remove_argument :name
12
+ argument :name, type: :string, default: "Role", banner: "Role"
10
13
  argument :user_cname, type: :string, default: "User", banner: "User"
11
14
 
15
+ def self.banner
16
+ "bin/rails generate role_fu [Role] [User] [options]\n\n" \
17
+ "Generates the Role model and the assignment join model, then links them to the User model.\n" \
18
+ " Usage:\n" \
19
+ " rails g role_fu # Generates 'Role' and links to 'User' (default)\n" \
20
+ " rails g role_fu Group # Generates 'Group' and links to 'User'\n" \
21
+ " rails g role_fu Group Account # Generates 'Group' and links to 'Account'"
22
+ end
23
+
24
+ desc ""
25
+
12
26
  def generate_models
13
27
  # Generate Role model
14
28
  template "role.rb.erb", "app/models/#{name.underscore}.rb"
@@ -29,7 +43,7 @@ module RoleFu
29
43
  " include RoleFu::Roleable\n"
30
44
  end
31
45
  else
32
- print_notes "User model #{user_cname} not found at #{user_path}. Please add 'include RoleFu::Roleable' manually."
46
+ say "User model #{user_cname} not found at #{user_path}. Please add 'include RoleFu::Roleable' manually."
33
47
  end
34
48
  end
35
49
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RoleFu
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: role_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Poimtsev
@@ -178,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0'
180
180
  requirements: []
181
- rubygems_version: 4.0.5
181
+ rubygems_version: 4.0.6
182
182
  specification_version: 4
183
183
  summary: A modern role management gem for Rails, replacing rolify.
184
184
  test_files: []