view_component-props 0.0.2 → 0.0.3
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 +13 -1
- data/README.md +24 -3
- data/lib/view_component-props.rb +3 -0
- data/lib/view_component_props/version.rb +1 -1
- data/lib/view_component_props.rb +9 -7
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 66db72b53902a7010dba206cb9d972732d5444d6e8ed454cb1e429248afcb442
|
|
4
|
+
data.tar.gz: df3f86322a1e183f450a28eab858f095e3e044e0d571d987347036cec5a6f346
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '084497d1655142ae2cc273faeaffe59308bbedf5957e6f724476074bd383c695c7c60067b67ade609da3bb900f25d1adee8fa3522ad3821381488fdf923fa1dd'
|
|
7
|
+
data.tar.gz: 124cb82395be740e128aebb5698edaceffd3aae227ece4087640e4fa4c6a8495f186391023eb726e2a5e58ba777c16ee1e86b22a194bf5961c0e9b8c7c9d24b2
|
data/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [X.X.X] - YYYY-MM-DD
|
|
9
9
|
|
|
10
|
-
## [0.0.
|
|
10
|
+
## [0.0.3] - 2026-05-30
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Dash-named entry file (`lib/view_component-props.rb`) so Bundler's default auto-require works for the published `view_component-props` gem name without a `require:` option
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- `ViewComponentProps.install!` now prepends its initializer instead of redefining `ViewComponent::Base#initialize`. This keeps the native initializer in the ancestor chain, so `super()` resolves to `ViewComponent::Base#initialize` rather than falling through to `ActionView::Base#initialize` and raising `ArgumentError` when a component is instantiated.
|
|
19
|
+
|
|
20
|
+
### Documentation
|
|
21
|
+
|
|
22
|
+
- Expanded the README casters section into a reference table and documented the nil-handling semantics (a `nil` value is never passed to a caster)
|
|
11
23
|
|
|
12
24
|
## [0.0.1] - 2026-05-29
|
|
13
25
|
|
data/README.md
CHANGED
|
@@ -89,9 +89,30 @@ end
|
|
|
89
89
|
|
|
90
90
|
### Casters
|
|
91
91
|
|
|
92
|
-
Built-in casters:
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
Built-in casters:
|
|
93
|
+
|
|
94
|
+
| Cast | Coerces to | Notes |
|
|
95
|
+
| ------------ | --------------------------- | --------------------------------------------------------------------------- |
|
|
96
|
+
| `:integer` | `Integer` | Via `Integer(value)`; raises `CastError` on non-numeric input. |
|
|
97
|
+
| `:float` | `Float` | Via `Float(value)`; raises `CastError` on non-numeric input. |
|
|
98
|
+
| `:string` | `String` | Via `value.to_s`. |
|
|
99
|
+
| `:symbol` | `Symbol` | Via `value.to_sym`. |
|
|
100
|
+
| `:boolean` | `true` / `false` | Uses `ActiveModel::Type::Boolean`, so `"0"`, `"false"`, `""` become `false`. |
|
|
101
|
+
| `:array` | `Array` | Via `Array(value)`, wrapping scalars in a one-element array. |
|
|
102
|
+
| `:hash` | `Hash` | Returns hashes unchanged; otherwise calls `value.to_h`. |
|
|
103
|
+
| `:decimal` | `BigDecimal` | Returns `BigDecimal` values unchanged; otherwise `BigDecimal(value.to_s)`. |
|
|
104
|
+
| `:date` | `Date` | Returns `Date` values unchanged; otherwise `Date.parse(value.to_s)`. |
|
|
105
|
+
| `:datetime` | `Time` / `ActiveSupport::TimeWithZone` | Returns `Time`/`DateTime` unchanged; otherwise parses via `Time.zone` (or `Time.parse` when no zone). |
|
|
106
|
+
|
|
107
|
+
#### Nil handling
|
|
108
|
+
|
|
109
|
+
A `nil` value is **never** passed to a caster — casting is short-circuited before the caster runs, so `nil` stays `nil`. This means casters don't need to be nil-safe, and a `nil` prop is never coerced into a placeholder like `""`, `0`, or `false`. Resolution order is:
|
|
110
|
+
|
|
111
|
+
1. The key's value (or `default:` when the key is missing) is resolved.
|
|
112
|
+
2. If that value is `nil` and a `fallback:` is defined, the fallback is resolved.
|
|
113
|
+
3. Only a non-`nil` result is handed to the caster; a `nil` result passes through untouched (then triggers `required:` if set).
|
|
114
|
+
|
|
115
|
+
Use `default:` or `fallback:` when you need a concrete value for a missing or `nil` prop. Note that fallbacks are resolved *before* casting, so a `fallback:` value is cast like any other value.
|
|
95
116
|
|
|
96
117
|
Register custom casters in the configuration block:
|
|
97
118
|
|
data/lib/view_component_props.rb
CHANGED
|
@@ -12,18 +12,20 @@ require_relative "view_component_props/definable"
|
|
|
12
12
|
require_relative "view_component_props/version"
|
|
13
13
|
|
|
14
14
|
module ViewComponentProps
|
|
15
|
+
module Initializer
|
|
16
|
+
def initialize(props = {})
|
|
17
|
+
super()
|
|
18
|
+
setup_props_for(props)
|
|
19
|
+
after_initialize
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
15
23
|
class << self
|
|
16
24
|
def install!(target = ViewComponent::Base)
|
|
17
25
|
return if target.include?(Definable)
|
|
18
26
|
|
|
19
27
|
target.include(Definable)
|
|
20
|
-
target.
|
|
21
|
-
def initialize(props = {})
|
|
22
|
-
super()
|
|
23
|
-
setup_props_for(props)
|
|
24
|
-
after_initialize
|
|
25
|
-
end
|
|
26
|
-
end
|
|
28
|
+
target.prepend(Initializer)
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: view_component-props
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kinnell Shah
|
|
@@ -84,6 +84,7 @@ files:
|
|
|
84
84
|
- CHANGELOG.md
|
|
85
85
|
- LICENSE
|
|
86
86
|
- README.md
|
|
87
|
+
- lib/view_component-props.rb
|
|
87
88
|
- lib/view_component_props.rb
|
|
88
89
|
- lib/view_component_props/casters.rb
|
|
89
90
|
- lib/view_component_props/casters/base.rb
|