attribeauty 0.3.3 → 0.3.4

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: 812191110b6c7f397737c3a9b1cceab66819c07d549c02c31687b8260342f404
4
- data.tar.gz: 2ce7d61531ba7dcb7a896994ef94a2fa970bd821eb62d0901cc2b1df5e70947b
3
+ metadata.gz: 04be2abe193a7faca2c172bb90713086e2a656bada649e0356ada8a444f54993
4
+ data.tar.gz: e86ca7fb0fbc2d8e20679be174a98eced95c6facf3d98d2b3d1983961e99a9c8
5
5
  SHA512:
6
- metadata.gz: dbe0d664e43e995eb4caf66f66fe2a242d2f40b9effda38f511775451c666c82e1596a9116197e5cc84848f0f63ab11f2bb0f537f2214e0d38c6f9b3ddba2e1f
7
- data.tar.gz: 66fb433c37a8986c4f5cf3bec0dae55246360fb6f65d82e2e25d1f507b3f4526d5476c99fa7f3e5244d6d255cdb9f429c51e7a7c7c84504e61fe2083e864bf0b
6
+ metadata.gz: 1fe0d80aca7c85b8a34bf233f8b72133f16b75eea1a1800e8046efe5df1b19612a060662dc4c80bbbcffd0462d8cf2dee229a1c36228bba155dcff1058d814a7
7
+ data.tar.gz: 42ab8159a2117c43956b84699f7ba9025a156e854e355f389424b810ecdfa90ee83f2fbdbdf71b43b650f723d1310288c18dc0f1e03f0f4765f193a8d58a1cc0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.4] - 2024-06-24
4
+
5
+ - tiny refactor
6
+
3
7
  ## [0.3.3] - 2024-06-24
4
8
 
5
9
  - handle nil in types. Big refactor
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- attribeauty (0.3.3)
4
+ attribeauty (0.3.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -44,17 +44,13 @@ module Attribeauty
44
44
  yield
45
45
  end
46
46
 
47
+ #
47
48
  def attribute(name, type = nil, **args, &block)
48
49
  value = request_params[name]
49
- return if value.nil? && args[:required].nil?
50
-
51
- if block_given?
52
- @to_h[name.to_sym] = vals_from_nested(value, &block)
53
- else
54
- validator = Validator.run(name, value, type, **args)
55
- @errors.push(*validator.errors)
56
- @to_h[name.to_sym] = validator.value if validator.valid?
57
- end
50
+ return if required?(value, **args)
51
+ return hash_from_nested(name, value, &block) if block_given?
52
+
53
+ value_from_validator(name, value, type, **args)
58
54
  end
59
55
 
60
56
  def inspect
@@ -71,17 +67,28 @@ module Attribeauty
71
67
 
72
68
  private
73
69
 
74
- def vals_from_nested(value, &block)
75
- if value.is_a?(Array)
76
- value.map do |val|
77
- params = self.class.with(val).accept(&block)
70
+ def required?(value, **args)
71
+ value.nil? && args[:required].nil?
72
+ end
73
+
74
+ def value_from_validator(name, value, type, **args)
75
+ validator = Validator.run(name, value, type, **args)
76
+ @errors.push(*validator.errors)
77
+ @to_h[name.to_sym] = validator.value if validator.valid?
78
+ end
79
+
80
+ def hash_from_nested(name, value, &block)
81
+ @to_h[name.to_sym] =
82
+ if value.is_a?(Array)
83
+ value.map do |val|
84
+ params = self.class.with(val).accept(&block)
85
+ @errors.push(*params.errors)
86
+ params.to_h
87
+ end.reject(&:empty?)
88
+ else
89
+ params = self.class.with(value).accept(&block)
78
90
  @errors.push(*params.errors)
79
91
  params.to_h
80
- end.reject(&:empty?)
81
- else
82
- params = self.class.with(value).accept(&block)
83
- @errors.push(*params.errors)
84
- params.to_h
85
92
  end
86
93
  end
87
94
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Attribeauty
4
- VERSION = "0.3.3"
4
+ VERSION = "0.3.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attribeauty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-24 00:00:00.000000000 Z
11
+ date: 2024-06-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: There are so many of these, I just needed this one.
14
14
  email: