recordables 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 +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/recordables/macros.rb +8 -3
- data/lib/recordables/nested_recordable_attributes.rb +12 -3
- data/lib/recordables/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2a183a373143cdec754a8704fb66131ddc8980930ebb3a6e16d7a42309bcdd1f
|
|
4
|
+
data.tar.gz: eb62d04c3f09067fa95221810da3cdcb4acdf704052ddd88059893735e7b521d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 33f79c5525fce7dc3cf40c345c77f38d99f7a511cafca9c7be1b5412b5177ca6dd3722346e7b3365ca7e2c71eb1fbc1d9c8c70ca03de34d6a78f0faacb3c2158
|
|
7
|
+
data.tar.gz: 60c51aa0167f1ac34132cab455cbace4275635f8be85157ac183f5394b26062e3e6506373c8fa7e9d59b6ec6b59bda517f5f1203fd14a8fada865b1e66a90eab
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,18 @@ All notable changes to this project are documented here. The format follows
|
|
|
8
8
|
|
|
9
9
|
### Added
|
|
10
10
|
|
|
11
|
+
- `nested_recordable_attributes_for` accepts `recording_attributes:`, an optional proc
|
|
12
|
+
called once per new child (with the parent record) to build extra attributes for that
|
|
13
|
+
child's Recording. Without it, `apply_#{plural}_attributes!` creating a new child had
|
|
14
|
+
no way to set anything beyond `actor:` and the child's own fields — any host app whose
|
|
15
|
+
Recording has its own required columns (an `account_id` or similar tenant column is
|
|
16
|
+
the common case) hit a hard `NOT NULL` failure the moment a form actually submitted a
|
|
17
|
+
new child row.
|
|
18
|
+
|
|
19
|
+
## [0.2.0]
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
11
23
|
- `trashable` — `default_scope` + `with_trashed` for a recordable type whose Recording
|
|
12
24
|
can be trashed, so a trashed row stops showing up in normal queries. Paired with
|
|
13
25
|
`Recording.active` and `Recording#trash!`.
|
data/lib/recordables/macros.rb
CHANGED
|
@@ -81,12 +81,17 @@ module Recordables
|
|
|
81
81
|
# class RoutineTemplate < ApplicationRecord
|
|
82
82
|
# recordable
|
|
83
83
|
# has_children :task_templates, class_name: "TaskTemplate"
|
|
84
|
-
# nested_recordable_attributes_for :task_templates, class_name: "TaskTemplate"
|
|
84
|
+
# nested_recordable_attributes_for :task_templates, class_name: "TaskTemplate",
|
|
85
|
+
# recording_attributes: ->(template) { { account: template.account } }
|
|
85
86
|
# end
|
|
86
|
-
|
|
87
|
+
#
|
|
88
|
+
# recording_attributes: only needed if the host app's Recording has its
|
|
89
|
+
# own required columns (an account_id or similar tenant column is the
|
|
90
|
+
# common case) — see Recordables::NestedRecordableAttributes.
|
|
91
|
+
def nested_recordable_attributes_for(plural_name, class_name: nil, recording_attributes: nil)
|
|
87
92
|
include Recordables::NestedRecordableAttributes
|
|
88
93
|
target_class_name = class_name&.to_s || plural_name.to_s.classify
|
|
89
|
-
__recordables_define_nested_attributes(plural_name, class_name: target_class_name)
|
|
94
|
+
__recordables_define_nested_attributes(plural_name, class_name: target_class_name, recording_attributes: recording_attributes)
|
|
90
95
|
end
|
|
91
96
|
|
|
92
97
|
# A belongs_to whose target is trashable, resolved through the append-only
|
|
@@ -7,9 +7,17 @@ module Recordables
|
|
|
7
7
|
# class RoutineTemplate < ApplicationRecord
|
|
8
8
|
# recordable
|
|
9
9
|
# has_children :task_templates, class_name: "TaskTemplate"
|
|
10
|
-
# nested_recordable_attributes_for :task_templates, class_name: "TaskTemplate"
|
|
10
|
+
# nested_recordable_attributes_for :task_templates, class_name: "TaskTemplate",
|
|
11
|
+
# recording_attributes: ->(template) { { account: template.account } }
|
|
11
12
|
# end
|
|
12
13
|
#
|
|
14
|
+
# recording_attributes: is only needed if the host app's Recording has its
|
|
15
|
+
# own required columns beyond what the gem's own template generates (an
|
|
16
|
+
# account_id or similar tenant column is the common case) — a new child's
|
|
17
|
+
# Recording needs those set too, and there's no attribute on the
|
|
18
|
+
# submitted form row itself to read them from. Called once per new child,
|
|
19
|
+
# with the parent record, right before creating it.
|
|
20
|
+
#
|
|
13
21
|
# accepts_nested_attributes_for can't work here: it writes at
|
|
14
22
|
# assign_attributes time, straight to a real association's rows — but
|
|
15
23
|
# task_templates isn't a real has_many (see HasChildren), and a child
|
|
@@ -30,7 +38,7 @@ module Recordables
|
|
|
30
38
|
extend ActiveSupport::Concern
|
|
31
39
|
|
|
32
40
|
class_methods do
|
|
33
|
-
def __recordables_define_nested_attributes(plural_name, class_name:)
|
|
41
|
+
def __recordables_define_nested_attributes(plural_name, class_name:, recording_attributes:)
|
|
34
42
|
singular_name = plural_name.to_s.singularize
|
|
35
43
|
target_class_name = class_name.to_s
|
|
36
44
|
pending_ivar = :"@pending_#{plural_name}_attributes"
|
|
@@ -88,7 +96,8 @@ module Recordables
|
|
|
88
96
|
child.recording.revise(actor: actor, **changes)
|
|
89
97
|
end
|
|
90
98
|
elsif !destroy && changes.present?
|
|
91
|
-
|
|
99
|
+
extra_recording_attrs = recording_attributes ? recording_attributes.call(self) : {}
|
|
100
|
+
public_send(:"add_#{singular_name}", actor: actor, recording: extra_recording_attrs, **changes)
|
|
92
101
|
end
|
|
93
102
|
end
|
|
94
103
|
|
data/lib/recordables/version.rb
CHANGED