trenchcoat 0.2.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +6 -4
- data/lib/trenchcoat/version.rb +1 -1
- data/lib/trenchcoat.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4a999d9179ee092b990f45eba56790ffb867fc8c7681e6d1c491e9421794f48
|
4
|
+
data.tar.gz: d5598b1853fed58ef5f188feff2633e26ad956ef73a25ede7912e1c014539e6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c4905138ac1431360d07532fd681636e2b8b9982d153ce3a891743c17cb073811bf064a86283e3f908ba3adc6831c061fa170a9f52851cf7b4c7bff283337c0
|
7
|
+
data.tar.gz: 0b75ccf44c4e0b1a5162dafd466be21d555cf57dc788d81388349b2dcd7cf7d7f07a70a9b598237edf922ee23fb612c805b9db244ee04a16ed7a42ff41533728
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.0] - 2025-08-18
|
4
|
+
|
5
|
+
- `quack_like` also delegates `new_record?`
|
6
|
+
- https://github.com/practical-computer/trenchcoat/pull/5
|
7
|
+
- `fallback_to_model_values` normalizes `original_attributes_hash`
|
8
|
+
- https://github.com/practical-computer/trenchcoat/pull/4
|
9
|
+
|
10
|
+
## [0.2.0] - 2025-05-07
|
11
|
+
|
12
|
+
- `copy_attribute_definitions` uses `type_for_attribute`, `fallback_to_model_values` checks `against original_attributes_hash`
|
13
|
+
- https://github.com/practical-computer/trenchcoat/pull/1
|
14
|
+
|
3
15
|
## [0.1.0] - 2025-05-06
|
4
16
|
|
5
17
|
- Initial release
|
data/README.md
CHANGED
@@ -41,10 +41,9 @@ class CustomForm
|
|
41
41
|
|
42
42
|
attr_accessor :post
|
43
43
|
|
44
|
-
copy_attribute_definitions(model_class: Post, attributes: %i[title published_at])
|
44
|
+
copy_attribute_definitions(model_class: Post, attributes: %i[title body published_at])
|
45
45
|
quack_like(model_instance_attr: :post)
|
46
46
|
|
47
|
-
attribute :body, :string # has to be manually defined because there is not a Text type for ActiveModel by default
|
48
47
|
attribute :is_published, :boolean, default: false
|
49
48
|
alias is_published? is_published
|
50
49
|
|
@@ -56,8 +55,11 @@ class CustomForm
|
|
56
55
|
published_at
|
57
56
|
|
58
57
|
self.post = Post.new if post.blank?
|
59
|
-
|
60
|
-
|
58
|
+
fallback_to_model_values(
|
59
|
+
model: post,
|
60
|
+
attributes_to_check: %i[title body published_at],
|
61
|
+
original_attributes_hash: attributes
|
62
|
+
)
|
61
63
|
|
62
64
|
return if attributes.key?(:is_published)
|
63
65
|
|
data/lib/trenchcoat/version.rb
CHANGED
data/lib/trenchcoat.rb
CHANGED
@@ -9,8 +9,9 @@ module Trenchcoat
|
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
11
|
def fallback_to_model_values(model:, attributes_to_check:, original_attributes_hash:)
|
12
|
+
indifferent_original_attributes = original_attributes_hash.to_h.with_indifferent_access
|
12
13
|
attributes_to_check.each do |attribute|
|
13
|
-
next if
|
14
|
+
next if indifferent_original_attributes.key?(attribute)
|
14
15
|
|
15
16
|
send(:"#{attribute}=", model.public_send(attribute))
|
16
17
|
end
|
@@ -27,7 +28,7 @@ module Trenchcoat
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def quack_like(model_instance_attr:)
|
30
|
-
delegate :model_name, :persisted?, :id, to: model_instance_attr
|
31
|
+
delegate :model_name, :persisted?, :new_record?, :id, to: model_instance_attr
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trenchcoat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Cannon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|