recourse 7.0.0 → 7.2.0

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: d4c5d237ba9ace6d0bde291127548ea5202ea729de90541d11240a5d2db0dae3
4
- data.tar.gz: 7f266eaa7ba56f045c692702fa94c4163d09621bedfd3eb963ab025af5efba39
3
+ metadata.gz: 95ef379a34df3d662d855df04690b3627584af8e5340d3bc7f9fd451569d6828
4
+ data.tar.gz: 6429eefa62d743af7e1071cac2bed85618fc36dba623551d14d01f62129b2ded
5
5
  SHA512:
6
- metadata.gz: c03bfff3a9f95fa135fd7aaf1b5b16e8c905dab9431d13bdc139aaf58cf5188d36164e1921260b6ba21fe3829bdea087bcefbf9f2082ddc73e06d6201ccee885
7
- data.tar.gz: c79417ff860145a2da9a5e987d842f9d7351e1a92c91916a65714ae83b68786f4f6c557d6e60cdd35dbed670d24974831490235a5127cb4f8437962576e7dd7d
6
+ metadata.gz: 487d50ea3bf02897f91807512d4624dd768b41483ccd5b4a4da74f4d3aa8e460c3491e3abe1739d13ca55480a985b9c93485112352c28bae5729c0969316f92b
7
+ data.tar.gz: 29540aff5c10c30fca2a7c79ac0fe6ad4f572d505be2a085dfc7f3675539941c0a67358a328a431a0d39974410665a5e7891c3511e88b93cb26926ba916d707e
data/CHANGELOG.md CHANGED
@@ -7,6 +7,32 @@ For more information about changelogs, check [Keep a Changelog](http://keepachan
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## 7.2.0 - 2026-09-20
11
+
12
+ * [CHANGE] A row a model will not give up says so, rather than raising
13
+
14
+ `destroy` was `destroy!`, so a `before_destroy` that threw `:abort` answered a reader
15
+ with a 500. The page keeps the row and says `Specialty could not be deleted.`, the way
16
+ an update that a validation turned down says what it says.
17
+
18
+ ## 7.1.0 - 2026-09-20
19
+
20
+ * [CHANGE] The card draws the button that deletes what the page is about
21
+
22
+ It was drawn by the gem's own `edit` template, so a host writing a template of its own
23
+ lost it and wrote `destroy_resource_button` back by hand. The card draws it now, the way
24
+ it draws the tabs and the buttons beside the trail, and a host's page is its body alone.
25
+
26
+ A record's own page carries it, whichever of the two is open, so a resource routed to be
27
+ read and deleted but never changed is deleted from the page that reads it. Nothing gains
28
+ the ability to delete what it could not: a route without `destroy` draws no button.
29
+
30
+ * [CHANGE] A column the database generates is never offered on a form
31
+
32
+ Postgres writes a stored generated column out of the others and takes no value for one,
33
+ so a field for it would be refused whatever was typed. Such a column is read on every
34
+ other screen as before.
35
+
10
36
  ## 7.0.0 - 2026-09-19
11
37
 
12
38
  * [BREAKING] What a page counts is the gem's to work out
@@ -23,7 +23,7 @@ module Recourse
23
23
  def destroy_resource(record)
24
24
  return super unless attachment_reflection
25
25
 
26
- attachment_of(record).destroy!
26
+ attachment_of(record).destroy
27
27
  end
28
28
 
29
29
  # Attached rather than assigned, which is the whole reason this exists. Rails'
@@ -24,7 +24,7 @@ module Recourse
24
24
 
25
25
  # And the record gone. `destroy!`, so a callback that stops one says so rather than
26
26
  # leaving the page claiming it worked.
27
- def destroy_resource(record) = record.destroy!
27
+ def destroy_resource(record) = record.destroy
28
28
 
29
29
  # A foreign key whose label is typed arrives as that label, so it is looked up
30
30
  # here. Nothing found leaves the key nil, and `belongs_to` reports it missing.
@@ -65,11 +65,14 @@ module Recourse
65
65
  end
66
66
  end
67
67
 
68
- # Deletes the record and shows the index without it. `destroy!`, so a callback that
69
- # stops one says so rather than leaving the page claiming it worked.
68
+ # Deletes the record and shows the index without it. A callback that stops one is
69
+ # answered where the record still is, rather than left to raise or to let the page
70
+ # claim it worked: a row a model refuses to give up is a page's business, not a 500.
70
71
  def destroy
71
- destroy_resource @recourse
72
- wrote t('recourse.deleted', model: human_name)
72
+ return wrote t('recourse.deleted', model: human_name) if destroy_resource @recourse
73
+
74
+ flash.alert = t('recourse.deleted_error', model: human_name)
75
+ redirect_back fallback_location: url_for(action: :index), status: :see_other
73
76
  end
74
77
 
75
78
  private
@@ -4,7 +4,10 @@
4
4
  <%# Every bare action the routes drew under this record: a nested resource with no
5
5
  index of its own is reached from nowhere, so its button sits beside the
6
6
  breadcrumbs wherever the record is shown, on whichever of its pages that is. -%>
7
+ <%# The button that deletes what the page is about, drawn here rather than in a template
8
+ so a host writing its own show or edit keeps it without asking. -%>
7
9
  <% content_for :actions do %>
10
+ <%= destroy_resource_button destroyable_record %>
8
11
  <% bare_action_buttons(record).each do |label, path, method| %>
9
12
  <%= button_to label, path, method:, form_class: 'ms-3',
10
13
  class: 'btn theme-primary btn-sm btn-solid' %>
@@ -1,7 +1,3 @@
1
1
  <% content_for :title, resource_record_label %>
2
2
 
3
- <% content_for :actions do %>
4
- <%= destroy_resource_button resource_record %>
5
- <% end %>
6
-
7
3
  <%= render 'form', resource_key => resource_record %>
@@ -50,6 +50,7 @@ en:
50
50
  darken: Dark
51
51
  delete: Delete %{model}
52
52
  deleted: "%{model} was deleted."
53
+ deleted_error: "%{model} could not be deleted."
53
54
  destroy: Delete
54
55
  exit: Exit
55
56
  displaying:
@@ -1,6 +1,14 @@
1
1
  # Reopened for the order a row reads in, which a table, a show page and a form all ask
2
2
  # for the same way.
3
3
  module Recourse
4
+ # Columns the database writes itself out of the others, which a form never offers: a
5
+ # stored generated column takes no value, and Postgres refuses the one a form would send.
6
+ # @param model [Class] the model the page is about.
7
+ # @return [Array<String>] the names of its generated columns.
8
+ def self.virtual_columns(model)
9
+ model.columns.select(&:virtual?).map(&:name)
10
+ end
11
+
4
12
  # Which part of a row a column belongs to. What a column holds is the gem's to know
5
13
  # and where the schema put it is the host's, so both have a say: the kind picks the
6
14
  # band, and the order inside the band is the one the table already has. Extended onto
@@ -7,11 +7,8 @@ module Recourse
7
7
 
8
8
  # The record whose card this page is drawn in: the parent, on a page nested under
9
9
  # one, and the record itself where the page is its look or its change. An index of
10
- # its own, and a form for a record that is not there yet, stand outside a card. A
11
- # host drawing a page whole says so by assigning `@recourse_card = false`.
10
+ # its own, and a form for a record that is not there yet, stand outside a card.
12
11
  def card_record
13
- return if controller_assign('recourse_card') == false
14
-
15
12
  resource_parent || (resource_record if controller.action_name.in? %w[show edit])
16
13
  end
17
14
 
@@ -12,10 +12,18 @@ module Recourse
12
12
 
13
13
  private
14
14
 
15
+ # The record a page may delete: the one it is about, on its own look or its own
16
+ # change page. A nested index wears the parent's card and deletes nothing from it.
17
+ # @api private
18
+ def destroyable_record
19
+ resource_record if controller.action_name.in? %w[show edit]
20
+ end
21
+
15
22
  # Deletes the record on the page, or nothing at all where no action is routed
16
23
  # to delete it with — the same two guards the edit link answers to.
24
+ # @api private
17
25
  def destroy_resource_button(record)
18
- path = destroy_resource_path record
26
+ path = record && destroy_resource_path(record)
19
27
  return unless path
20
28
 
21
29
  confirm_button_to t('recourse.delete', model: resource_name), path,
@@ -24,6 +32,7 @@ module Recourse
24
32
  form_class: 'd-inline-block'
25
33
  end
26
34
 
35
+ # @api private
27
36
  # What deleting this record takes with it, counted a level down and no further:
28
37
  # a state reaches counties, then ZIPs, then locations, and counting that far
29
38
  # would join 40,965 rows to draw one page.
@@ -25,10 +25,12 @@ module Recourse
25
25
  # `%i[created_at updated_at]` asks for the two Rails keeps rather than the two
26
26
  # a record is about. A timestamp named here still lands last, and in that order,
27
27
  # whichever way round it was written.
28
+ # @api private
28
29
  def recourse_displayed = []
29
30
 
30
31
  # `ZIP code`: what to call a foreign key pointing here. A form's label, a table's
31
32
  # heading and a search prompt all name the same thing, so they name it once.
33
+ # @api private
32
34
  def recourse_reference_name
33
35
  attribute = Recourse.downcase human_attribute_name(recourse_label)
34
36
 
@@ -37,6 +39,7 @@ module Recourse
37
39
 
38
40
  # True when the label has a length, so it is short enough to be typed and a
39
41
  # form can ask for the value instead of listing every record to pick from.
42
+ # @api private
40
43
  def recourse_typed_label?
41
44
  validators_on(recourse_label).any? ActiveModel::Validations::LengthValidator
42
45
  end
@@ -2,6 +2,7 @@ module Recourse
2
2
  module Searchable
3
3
  # What a model's own schema offers a search: which of its columns are worth
4
4
  # looking through, and which of its foreign keys are worth looking past.
5
+ # @api private
5
6
  module Columns
6
7
  # Column types a search box can match on containment. An enum is a Postgres
7
8
  # type of its own, and what it holds is a word, so it reads as a string too.
@@ -15,6 +15,7 @@ module Recourse
15
15
  # and the labels behind foreign keys — less the one `except:` names — on
16
16
  # containment; or, for a model that keeps nothing in plaintext worth
17
17
  # searching, its encrypted columns, whole.
18
+ # @api private
18
19
  def recourse_search_terms(except: nil)
19
20
  plain = recourse_searchable_columns + recourse_searchable_references(except:)
20
21
  return [plain, 'cont'] if plain.any?
@@ -23,6 +24,7 @@ module Recourse
23
24
  end
24
25
 
25
26
  # Those same terms as words, lower case but for the acronyms among them.
27
+ # @api private
26
28
  def recourse_search_names(except: nil)
27
29
  fields, = recourse_search_terms(except:)
28
30
 
@@ -33,6 +35,7 @@ module Recourse
33
35
 
34
36
  # A term is a column of this model, or a `zip_code` reaching through one of its
35
37
  # foreign keys — which a form and a table already have a name for.
38
+ # @api private
36
39
  def recourse_term_name(field)
37
40
  reached = recourse_searchable_associations.find { |one| field.start_with? "#{one.name}_" }
38
41
  return reached.klass.recourse_reference_name if reached
@@ -47,11 +47,13 @@ module Recourse
47
47
  # True where a foreign key pointing here is typed rather than picked, which a
48
48
  # form and the controller reading its parameters back have to agree on: the label
49
49
  # is bounded, or the table is too long to list.
50
+ # @api private
50
51
  def recourse_typed_reference? = recourse_typed_label? || !recourse_listable?
51
52
 
52
53
  # True where every row of this model could be listed in one menu. The count is
53
54
  # bounded, so the question costs the same on ten rows as on ten million, and it
54
55
  # is asked once per class — a table that crosses the line is noticed at boot.
56
+ # @api private
55
57
  def recourse_listable?
56
58
  return @recourse_listable unless @recourse_listable.nil?
57
59
 
@@ -1,4 +1,4 @@
1
1
  module Recourse
2
2
  # Version of the gem, read by the gemspec and by hosts checking compatibility.
3
- VERSION = '7.0.0'
3
+ VERSION = '7.2.0'
4
4
  end
data/lib/recourse.rb CHANGED
@@ -59,10 +59,11 @@ module Recourse
59
59
 
60
60
  # Columns a user may set: the form offers these, the show page reads these out, and
61
61
  # `create` permits these. A counter cache is none of a user's business — Rails keeps
62
- # it, so a form that offered one would let it be typed over.
62
+ # it, so a form that offered one would let it be typed over, and neither is a column
63
+ # the database generates: it takes no value at all.
63
64
  def self.editable_columns(model)
64
65
  ordered model, model.column_names - ['id', *TIMESTAMPS] - counters(model).keys -
65
- hidden_columns(model)
66
+ hidden_columns(model) - virtual_columns(model)
66
67
  end
67
68
 
68
69
  # Columns no screen shows: whatever the model asked to hide through `recourse_hidden`
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recourse
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - claudiob