cafe_car 0.2.0 → 0.2.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: 7349873b72f79f05fd45bdb30e1a474b0d89d0b8352172378f6cecd239cc4f56
4
- data.tar.gz: 1c2dcb971ecb7426bd168add0ffd46bff5fff204600e6f125aaa853db983feea
3
+ metadata.gz: 8f2ee78455723f808d6f02bbcad83ac86cd5f4fcf8c05203bd3afc602afe1d4f
4
+ data.tar.gz: '09447696c9bd504e776cc1cc493025ff99ceb467276ca916eb660165bfdf42cc'
5
5
  SHA512:
6
- metadata.gz: 7d9aebfaa9fec6e15149003739dab554bcd1e3279c66ef040fba72656b8d916c411cac39e05589e08e3b95b28a77311fac6875068e9a6f527f73c8a16d43fbe7
7
- data.tar.gz: 037c7c894cd5c161e3c3544195074888d71166a6504e5e3115cd660372ac4038d793a1e78ab65713e760a49d019ff32717b73c99eba59a62fe935234705adfde
6
+ metadata.gz: b39a51b42de3e8ffa3440e3d714eab15415592e30077187ddabf970826f64ef210d7f4f3e6a61ef28de43e0c8715dbaba35367700d1f2537fad3817c16b347ee
7
+ data.tar.gz: 30792c4c93baf653babd0f2bb64dc0790875faa41db6ef7d5dcf93e69238c146752930794a2672f68eee83c15facfb537b200825750b370d2199e79dc627cc2e
data/README.md CHANGED
@@ -33,6 +33,55 @@ an application-wide or model-specific basis.
33
33
 
34
34
  **Perfect for**: Admin panels, internal tools, and rapid prototyping.
35
35
 
36
+ ## Table of Contents
37
+
38
+ - [How CafeCar compares](#how-cafecar-compares)
39
+ - [Features](#features)
40
+ - [Prerequisites](#prerequisites)
41
+ - [Installation](#installation)
42
+ - [Getting Started](#getting-started)
43
+ - [Core Components](#core-components)
44
+ - [Controllers](#controllers)
45
+ - [Policies](#policies)
46
+ - [Presenters](#presenters)
47
+ - [UI Components](#ui-components)
48
+ - [Forms](#forms)
49
+ - [Filtering & Sorting](#filtering--sorting)
50
+ - [Advanced Usage](#advanced-usage)
51
+ - [Sessions & Authentication](#sessions--authentication)
52
+ - [Generators](#generators)
53
+ - [Resource Generator](#resource-generator)
54
+ - [Controller Generator](#controller-generator)
55
+ - [Policy Generator](#policy-generator)
56
+ - [Notes Generator](#notes-generator)
57
+ - [Sessions Generator](#sessions-generator)
58
+ - [Configuration](#configuration)
59
+ - [Testing](#testing)
60
+ - [Contributing](#contributing)
61
+ - [License](#license)
62
+
63
+ ## How CafeCar compares
64
+
65
+ CafeCar is convention-first. Rather than a separate admin app with its own DSL,
66
+ it extends Rails' own view layer: a plain model renders a working admin with
67
+ essentially no configuration, and you extend it with the Rails you already know
68
+ — controllers, Pundit policies, presenters, and ERB. There's no new query
69
+ language or admin framework to learn; you stay in Rails.
70
+
71
+ The established alternatives are all solid, and each fits a different taste.
72
+ Reach for one of them when its model matches how you want to work:
73
+
74
+ | Gem | Reach for it when… | Trade-off |
75
+ | --- | --- | --- |
76
+ | **ActiveAdmin** | You want a mature, batteries-included admin with a rich registration DSL. | You author screens in its Arbre/Ruby DSL rather than plain Rails views. |
77
+ | **Avo** | You prefer defining resources through configuration and want polished paid Pro features. | Config-driven, and the richer tiers are commercial. |
78
+ | **Administrate** | You want to scaffold controllers and views you fully own and edit. | You maintain the generated code as your app grows. |
79
+ | **RailsAdmin** | You want an admin mounted as an engine with almost zero setup. | Heavy runtime introspection and less conventional customization. |
80
+ | **Trestle** | You like a modular, DSL-driven admin with a built-in UI toolkit. | Another admin DSL to learn alongside Rails. |
81
+
82
+ Reach for CafeCar when you want a Rails-native, convention-over-configuration
83
+ admin that you extend with ordinary Rails code.
84
+
36
85
  ## Features
37
86
 
38
87
  - 🚀 **Auto-generated CRUD interfaces** - One line of code generates complete
@@ -79,7 +128,7 @@ $ rails generate cafe_car:install
79
128
 
80
129
  This will:
81
130
 
82
- - Add required gems (cnc, bcrypt, paper_trail, factory_bot_rails, faker, rouge)
131
+ - Add required gems (bcrypt, paper_trail, factory_bot_rails, faker, rouge)
83
132
  plus development tools (hotwire-livereload, better_errors, binding_of_caller,
84
133
  chrome_devtools_rails, i18n-debug)
85
134
  - Mount the CafeCar engine at `/` under the `:admin` namespace
@@ -23,10 +23,17 @@ module CafeCar
23
23
  end
24
24
 
25
25
  def current_user
26
- current_session.user
26
+ current_session&.user
27
27
  end
28
28
 
29
+ # No session without the opt-in infrastructure. Pundit evaluates
30
+ # `current_user` (its default `pundit_user`) on every authorized request, so
31
+ # building a session here would 500 a CRUD-only host that never ran
32
+ # `cafe_car:sessions`. Gate on `sessions_available?` so it degrades to a nil
33
+ # user (→ 403) instead.
29
34
  def current_session
35
+ return unless sessions_available?
36
+
30
37
  CafeCar[:Current].session ||= find_session_by_cookie || build_session
31
38
  end
32
39
 
@@ -1,3 +1,3 @@
1
1
  module CafeCar
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -22,19 +22,28 @@ class CafeCar::PolicyGenerator < Rails::Generators::NamedBase
22
22
 
23
23
  def model_class = file_path.classify.safe_constantize
24
24
 
25
- def model = @model ||= CafeCar[:ModelInfo].new(model_class)
25
+ def model = @model ||= CafeCar[:ModelInfo].new(model: model_class)
26
26
 
27
27
  def attribute_names
28
- @attribute_names ||= permitted.presence || model.fields.editable.map(&:method)
28
+ @attribute_names ||= permitted.presence || model_fields
29
+ end
30
+
31
+ # Introspect the model's editable columns, but only when it resolves to a
32
+ # loaded constant — a resource run writes the model file first but may not
33
+ # have autoloaded it yet, in which case the caller forwards explicit fields.
34
+ def model_fields
35
+ return [] if model_class.nil?
36
+
37
+ model.fields.editable.map(&:method)
29
38
  end
30
39
 
31
40
  def title_attribute
32
- return ":could_not_find_model" if model_class.nil?
41
+ return ":could_not_find_model" if attribute_names.blank?
33
42
  attribute_names.first.then { ":#{_1}" }
34
43
  end
35
44
 
36
45
  def permitted_attributes
37
- return ":create_model_first_to_generate_attributes" if model_class.nil?
46
+ return ":create_model_first_to_generate_attributes" if attribute_names.blank?
38
47
 
39
48
  # TODO: replace *_digest with * and *_confirmation
40
49
  # TODO: handle attachments
@@ -16,11 +16,17 @@ class CafeCar::ResourceGenerator < Rails::Generators::NamedBase
16
16
  end
17
17
 
18
18
  def create_policy
19
- generate "cafe_car:policy", file_path, force
19
+ generate "cafe_car:policy", file_path, *field_names, force
20
20
  end
21
21
 
22
22
  private
23
23
 
24
+ # The policy generator wants bare field names (`name price`), not the model
25
+ # generator's `field:type:index` form. Forwarding them lets the policy list
26
+ # real permitted attributes instead of falling back to model introspection,
27
+ # which can't see a model that isn't a loaded constant yet mid-run.
28
+ def field_names = attributes.map { _1.to_s.split(":").first }
29
+
24
30
  def assign_controller_names!(...)
25
31
  if options[:model_name].blank?
26
32
  assign_names!(file_name)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cafe_car
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Peterson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-30 00:00:00.000000000 Z
11
+ date: 2026-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails