guide-rail 0.1.0 → 0.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: 64fe06eb07e4fc4e1e9865e8f7474185539e90bd2b695c102ea9771045d741b6
4
- data.tar.gz: cb166474c8ae652c3b0ee6ce95b6deb655f8b1270b65d0fe661dc3acbf1e2905
3
+ metadata.gz: a653787b5c034417b04462b539eb9285351490e239654be9f1a60085d6b381bf
4
+ data.tar.gz: e119dca807cda462cd12be68662970541785bfe833eb1166bb28f5ab0c999bbd
5
5
  SHA512:
6
- metadata.gz: 7aa7500eb8a49610ac77071bc42ed51b5711801293c85f418e6106fc8ed218dab4800ed6ec1c6b0025ea7a00a2a1e780a52999b01d31c71359b7b43020332b39
7
- data.tar.gz: d6077ef99145c833e73a3f485094ee658ab1c9c924a1ec34f46d634f5d67b3618d187f010d8d19c2bf2cdba3d5759171fd4d1551ff1546ed0c9f5f0a4ef338ab
6
+ metadata.gz: cbc8e1f706dadaf88c43c799ebc0e5c886a2b5b8165f595e962a5be60b62e6cd4bdadcc7d58c3adefc84338780b2186cea41294869d247ddb8d4254d377cfdfe
7
+ data.tar.gz: '08617c33b88592a995ca6d788e25cc46466e610082a81ca7102d2293cc1ba3732c96761f6aab19565d1900b3a76b615cde82adae91c844929b6bfd72b9d3f145'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.2.0] - 2026-11-21
2
+
3
+ - **Breaking**: values of the generated Data object come from the schema result ( `Dry::Schema::Result#to_h` ) instead of the input
4
+ - with `Dry::Schema.Params`, coerced values are set ( e.g. `"20"` -> `20`, `"off"` -> `false`, `""` -> `nil` for `maybe` )
5
+ - String keys and `HashWithIndifferentAccess` input are accepted with `Dry::Schema.Params` ( set `nil` before )
6
+ - keys not in the schema are dropped, including those in nested Hashes
7
+ - Fix `renderable` with `Dry::Schema.define` ( raised `ArgumentError` )
8
+ - README examples use `Dry::Schema.define`
9
+
1
10
  ## [0.1.0] - 2025-07-05
2
11
 
3
12
  - Initial release
data/README.md CHANGED
@@ -43,7 +43,7 @@ $ bundle add guide-rail
43
43
  ```ruby
44
44
  require "guide-rail"
45
45
 
46
- SimpleNonNullableSchema = Dry::Schema.Params do
46
+ SimpleNonNullableSchema = Dry::Schema.define do
47
47
  required(:name).filled(:string)
48
48
  end
49
49
 
@@ -54,7 +54,7 @@ class SimpleNonNullableCreator
54
54
  class_name :SimpleNonNullable
55
55
  end
56
56
 
57
- SimpleNonNullableCreator.from(name: nil) # => #<Dry::Schema::Result{name: nil} errors={name: ["must be filled"]} path=[]>
57
+ SimpleNonNullableCreator.from(name: nil) # => #<Dry::Schema::Result{name: nil} errors={name: ["must be a string"]} path=[]>
58
58
  SimpleNonNullableCreator.from(name: "John") # => #<data SimpleNonNullable name="John">
59
59
  SimpleNonNullableCreator.from({}) # => #<Dry::Schema::Result{} errors={name: ["is missing"]} path=[]>
60
60
  ```
@@ -62,7 +62,7 @@ SimpleNonNullableCreator.from({}) # => #<Dry::Schema::Result{} errors={name: ["i
62
62
  ### Nullable Object with `renderable` option
63
63
 
64
64
  ```ruby
65
- SimpleNullableSchema = Dry::Schema.Params do
65
+ SimpleNullableSchema = Dry::Schema.define do
66
66
  required(:name).maybe(:string)
67
67
  end
68
68
 
@@ -86,7 +86,7 @@ You can give a block to Creator class, the generated Data class can be extended
86
86
  This can be used to define decorator methods and conversion processes, so the generated Data class can also be used as a so-called ViewModel.
87
87
 
88
88
  ```ruby
89
- OptionalSchema = Dry::Schema.Params do
89
+ OptionalSchema = Dry::Schema.define do
90
90
  optional(:name).filled(:string)
91
91
  end
92
92
 
@@ -108,10 +108,35 @@ end
108
108
  OptionalAndYieldAccepter.from({}).name.start_with? "decorated" # => true
109
109
  ```
110
110
 
111
+ ### Choosing a schema
112
+
113
+ Values of the generated Data object come from the schema result, not from the input as is. So the Data object has the values the schema validated.
114
+
115
+ Use `Dry::Schema.define` for typed data such as hand-made Hashes or ActiveModel. Values are not coerced, and the Data object has the input values as is.
116
+
117
+ Use `Dry::Schema.Params` for HTTP params. String keys are accepted, and values are coerced before validation.
118
+
119
+ ```ruby
120
+ AgeSchema = Dry::Schema.Params do
121
+ required(:age).filled(:integer)
122
+ end
123
+
124
+ class AgeCreator
125
+ extend GuideRail
126
+
127
+ schema AgeSchema
128
+ class_name :Age
129
+ end
130
+
131
+ AgeCreator.from("age" => "20") # => #<data Age age=20>
132
+ ```
133
+
134
+ In both cases, keys not in the schema are dropped, including those in nested Hashes.
135
+
111
136
  ### Monadic mode
112
137
 
113
138
  ```ruby
114
- SimpleNonNullableSchema = Dry::Schema.Params do
139
+ SimpleNonNullableSchema = Dry::Schema.define do
115
140
  required(:name).filled(:string)
116
141
  end
117
142
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GuideRail
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/guide_rail.rb CHANGED
@@ -67,12 +67,14 @@ module GuideRail
67
67
  Object.const_get @_class
68
68
 
69
69
  if result.success?
70
+ # values come from schema result ( coerced and filtered by schema ), not from input
71
+ values = result.to_h
70
72
  new_value = Object.const_get(@_class).new(
71
73
  *(
72
74
  if @_renderable
73
- to_renderable(acceptance)
75
+ to_renderable(values)
74
76
  else
75
- acceptance
77
+ values
76
78
  end
77
79
  ).values_at(*@_attrs).map(&:freeze)
78
80
  )
@@ -122,7 +124,7 @@ module GuideRail
122
124
  case e
123
125
  when Hash
124
126
  [e.keys.first.to_sym, renderable_default(e.values.first)]
125
- when String
127
+ when String, Symbol # Params dumps String keys, define dumps Symbol keys
126
128
  [e.to_sym, ""]
127
129
  end
128
130
  }.flatten]
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guide-rail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - wtnabe
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 2025-07-06 00:00:00.000000000 Z
11
+ date: 2026-11-21 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: dry-schema
@@ -64,6 +65,7 @@ metadata:
64
65
  homepage_uri: https://github.com/wtnabe/guide-rail
65
66
  source_code_uri: https://github.com/wtnabe/guide-rail
66
67
  changelog_uri: https://github.com/wtnabe/guide-rail/blob/main/CHANGELOG.md
68
+ post_install_message:
67
69
  rdoc_options: []
68
70
  require_paths:
69
71
  - lib
@@ -78,7 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
80
  - !ruby/object:Gem::Version
79
81
  version: '0'
80
82
  requirements: []
81
- rubygems_version: 3.6.2
83
+ rubygems_version: 3.5.22
84
+ signing_key:
82
85
  specification_version: 4
83
86
  summary: A factory library to create safe, immutable Data objects from various sources
84
87
  using dry-schema and Data ( Ruby 3.2+ ).