dry-struct 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +16 -2
- data/Gemfile +3 -0
- data/dry-struct.gemspec +2 -3
- data/lib/dry/struct.rb +12 -9
- data/lib/dry/struct/class_interface.rb +6 -2
- data/lib/dry/struct/constructor.rb +1 -0
- data/lib/dry/struct/errors.rb +0 -4
- data/lib/dry/struct/version.rb +1 -1
- metadata +14 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33a4358e2a11c38b8816778acc5722b6d08a4c4d
|
4
|
+
data.tar.gz: 24bebcf82ec2e1dcb7536216acc397ae9aa6a3c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 332a625be1cde86fefd74efe78e79b375c6c66a15f5ad062f26e736055b9a9e9aef9234299bd0a7ff0272ce2e80218060d0ddb52d0074a5bc7d1ed12a03e1971
|
7
|
+
data.tar.gz: 757d33e5151cf3f30ffbe28798f1c86ab634f12612d4a7603431aae72513eedf088a3cf483603809b10ac6da870da2dc2f39ef1136e6fe99c42b25ee979ea681
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,18 @@
|
|
1
|
-
# v0.
|
1
|
+
# v0.4.0 2017-11-04
|
2
|
+
|
3
|
+
## Changed
|
4
|
+
|
5
|
+
* Attribute readers don't override existing instance methods (solnic)
|
6
|
+
* `Struct#new` uses raw attributes instead of method calls, this makes the behavior consistent with the change above (flash-gordon)
|
7
|
+
* `constructor_type` now actively rejects `:weak` and `:symbolized` values (GustavoCaso)
|
8
|
+
|
9
|
+
## Fixed
|
10
|
+
|
11
|
+
* `Struct#new` doesn't call `.to_hash` recursively (flash-gordon)
|
12
|
+
|
13
|
+
[Compare v0.3.1...v0.4.0](https://github.com/dry-rb/dry-struct/compare/v0.3.1...v0.4.0)
|
14
|
+
|
15
|
+
# v0.3.1 2017-06-30
|
2
16
|
|
3
17
|
## Added
|
4
18
|
|
@@ -6,7 +20,7 @@
|
|
6
20
|
* `Struct.attribute?` and `Struct.attribute_names` for introspecting struct attributes (flash-gordon)
|
7
21
|
* `Struct#__new__` is a safe-to-use-in-gems alias for `Struct#new` (flash-gordon)
|
8
22
|
|
9
|
-
[Compare v0.3.0...
|
23
|
+
[Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-struct/compare/v0.3.0...v0.3.1)
|
10
24
|
|
11
25
|
# v0.3.0 2017-05-05
|
12
26
|
|
data/Gemfile
CHANGED
@@ -2,9 +2,12 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
+
gem 'dry-types', git: 'https://github.com/dry-rb/dry-types'
|
6
|
+
|
5
7
|
group :test do
|
6
8
|
gem 'codeclimate-test-reporter', platform: :mri, require: false
|
7
9
|
gem 'simplecov', require: false
|
10
|
+
gem 'warning' if RUBY_VERSION >= '2.4.0'
|
8
11
|
end
|
9
12
|
|
10
13
|
group :tools do
|
data/dry-struct.gemspec
CHANGED
@@ -27,9 +27,8 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.require_paths = ['lib']
|
28
28
|
|
29
29
|
spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
|
30
|
-
spec.add_runtime_dependency 'dry-
|
31
|
-
spec.add_runtime_dependency 'dry-
|
32
|
-
spec.add_runtime_dependency 'dry-core', '~> 0.3'
|
30
|
+
spec.add_runtime_dependency 'dry-types', '~> 0.12', '>= 0.12.2'
|
31
|
+
spec.add_runtime_dependency 'dry-core', '~> 0.4', '>= 0.4.1'
|
33
32
|
spec.add_runtime_dependency 'ice_nine', '~> 0.11'
|
34
33
|
|
35
34
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
data/lib/dry/struct.rb
CHANGED
@@ -70,6 +70,8 @@ module Dry
|
|
70
70
|
defines :schema
|
71
71
|
schema EMPTY_HASH
|
72
72
|
|
73
|
+
CONSTRUCTOR_TYPE = Dry::Types['symbol'].enum(:permissive, :schema, :strict, :strict_with_defaults)
|
74
|
+
|
73
75
|
# Sets or retrieves {#constructor} type as a symbol
|
74
76
|
#
|
75
77
|
# @note All examples below assume that you have defined {Struct} with
|
@@ -107,13 +109,6 @@ module Dry
|
|
107
109
|
# 3. Input contains nil for a value that specifies a default
|
108
110
|
# 4. Input includes a key that was not specified in the schema
|
109
111
|
#
|
110
|
-
# @note Don’t use `:weak` and `:symbolized` as {#constructor_type},
|
111
|
-
# and instead use [`dry-validation`][] to process and validate
|
112
|
-
# attributes, otherwise your struct will behave as a data validator
|
113
|
-
# which raises exceptions on invalid input (assuming your attributes
|
114
|
-
# types are strict)
|
115
|
-
# [`dry-validation`]: https://github.com/dry-rb/dry-validation
|
116
|
-
#
|
117
112
|
# @example `:permissive` constructor
|
118
113
|
# class User < Dry::Struct
|
119
114
|
# constructor_type :permissive
|
@@ -177,7 +172,7 @@ module Dry
|
|
177
172
|
# @overload constructor_type
|
178
173
|
# Returns the constructor type for {Struct}
|
179
174
|
# @return [Symbol] (:strict)
|
180
|
-
defines :constructor_type
|
175
|
+
defines :constructor_type, type: CONSTRUCTOR_TYPE
|
181
176
|
constructor_type :permissive
|
182
177
|
|
183
178
|
# @return [Dry::Equalizer]
|
@@ -254,9 +249,17 @@ module Dry
|
|
254
249
|
# rom_n_roda.new(subtitle: '3nd edition')
|
255
250
|
# #=> #<Book title="Web Development with ROM and Roda" subtitle="3nd edition">
|
256
251
|
def new(changeset)
|
257
|
-
self.class[
|
252
|
+
self.class[__attributes__.merge(changeset)]
|
258
253
|
end
|
259
254
|
alias_method :__new__, :new
|
255
|
+
|
256
|
+
# @return[Hash{Symbol => Object}]
|
257
|
+
# @api private
|
258
|
+
def __attributes__
|
259
|
+
self.class.attribute_names.each_with_object({}) do |key, h|
|
260
|
+
h[key] = instance_variable_get(:"@#{ key }")
|
261
|
+
end
|
262
|
+
end
|
260
263
|
end
|
261
264
|
end
|
262
265
|
|
@@ -10,6 +10,7 @@ module Dry
|
|
10
10
|
module ClassInterface
|
11
11
|
include Core::ClassAttributes
|
12
12
|
|
13
|
+
include Dry::Types::Type
|
13
14
|
include Dry::Types::Builder
|
14
15
|
|
15
16
|
# @param [Class] klass
|
@@ -65,7 +66,10 @@ module Dry
|
|
65
66
|
schema schema.merge(new_schema)
|
66
67
|
input Types['coercible.hash'].public_send(constructor_type, schema)
|
67
68
|
|
68
|
-
|
69
|
+
new_schema.each_key do |key|
|
70
|
+
attr_reader(key) unless instance_methods.include?(key)
|
71
|
+
end
|
72
|
+
|
69
73
|
equalizer.instance_variable_get('@keys').concat(new_schema.keys)
|
70
74
|
|
71
75
|
self
|
@@ -200,7 +204,7 @@ module Dry
|
|
200
204
|
#
|
201
205
|
# @return [Array<Symbol>]
|
202
206
|
def attribute_names
|
203
|
-
schema.keys
|
207
|
+
@attribute_names ||= schema.keys
|
204
208
|
end
|
205
209
|
end
|
206
210
|
end
|
data/lib/dry/struct/errors.rb
CHANGED
data/lib/dry/struct/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-equalizer
|
@@ -24,54 +24,46 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.2'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: dry-configurable
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.1'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.1'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: dry-types
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
33
|
+
version: '0.12'
|
48
34
|
- - ">="
|
49
35
|
- !ruby/object:Gem::Version
|
50
|
-
version: 0.
|
36
|
+
version: 0.12.2
|
51
37
|
type: :runtime
|
52
38
|
prerelease: false
|
53
39
|
version_requirements: !ruby/object:Gem::Requirement
|
54
40
|
requirements:
|
55
41
|
- - "~>"
|
56
42
|
- !ruby/object:Gem::Version
|
57
|
-
version: '0.
|
43
|
+
version: '0.12'
|
58
44
|
- - ">="
|
59
45
|
- !ruby/object:Gem::Version
|
60
|
-
version: 0.
|
46
|
+
version: 0.12.2
|
61
47
|
- !ruby/object:Gem::Dependency
|
62
48
|
name: dry-core
|
63
49
|
requirement: !ruby/object:Gem::Requirement
|
64
50
|
requirements:
|
65
51
|
- - "~>"
|
66
52
|
- !ruby/object:Gem::Version
|
67
|
-
version: '0.
|
53
|
+
version: '0.4'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.4.1
|
68
57
|
type: :runtime
|
69
58
|
prerelease: false
|
70
59
|
version_requirements: !ruby/object:Gem::Requirement
|
71
60
|
requirements:
|
72
61
|
- - "~>"
|
73
62
|
- !ruby/object:Gem::Version
|
74
|
-
version: '0.
|
63
|
+
version: '0.4'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.4.1
|
75
67
|
- !ruby/object:Gem::Dependency
|
76
68
|
name: ice_nine
|
77
69
|
requirement: !ruby/object:Gem::Requirement
|