api-regulator 0.1.9 → 0.1.11

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: c1d041ae7a972c291795b539d3543fbda9da721c10f505966af5eca71c00fac4
4
- data.tar.gz: 592189f17e96f0c676adb9d393698ae32617a6f9558b5a255911b97ea422b6b9
3
+ metadata.gz: beb1b2f02d84500f7a1075c188c72f140ae936ff5c8a0d8e2cf74564a33215b6
4
+ data.tar.gz: b2c01f8fd7ae1c0dabe91777d408a0ea8680db49251c9c97471ddffa5c97e8de
5
5
  SHA512:
6
- metadata.gz: 29f9365bde56835debcffe256e6496d0cf3e8a9abe09aebeb88493141e893b38943cdfe83116cfd1bb7f1e95b73e59281849977b76834731cbf5d6ab022154ff
7
- data.tar.gz: 2c3bcd87b072eb9cb5877d15224a1782c9a90e16700050cb9d594367c741a2d8d27da992ca0c99d9f48e6ea959390e93ca44d6fa1b0099aafb861f97cf68cc74
6
+ metadata.gz: 572709a0fe03ddef58b7e843143ba07e97cac8bb28019ea5c0ac56cdef3292868e7f25846408e019327be457a72d63e90f9302a41f37cb933b694f5030d06b27
7
+ data.tar.gz: 201970e5d1eb3edfc12ef12f2c18ff8e45dd7a401cc4d7c8f59a47dd0eceeea80aabf268cf48fccd85fceb616645151bf57b1b59f2eecdb575ec6270f5a861ca
@@ -0,0 +1,26 @@
1
+ name: Release Gem
2
+
3
+ on:
4
+ workflow_dispatch: # Manual trigger
5
+
6
+ jobs:
7
+ release:
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - name: Checkout code
12
+ uses: actions/checkout@v4
13
+
14
+ - name: Set up Ruby
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: '3.3.6'
18
+ bundler-cache: true
19
+
20
+ - name: Build and Push Gem
21
+ env:
22
+ GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
23
+ run: |
24
+ chmod +x bin/release
25
+ bin/release
26
+
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api-regulator (0.1.9)
4
+ api-regulator (0.1.11)
5
5
  activemodel (~> 8.0)
6
6
  activesupport (~> 8.0)
7
7
 
@@ -29,9 +29,8 @@ module ApiRegulator
29
29
  attribute full_key, param.type if param.type
30
30
  self.defined_attributes += [full_key]
31
31
 
32
- # Add validations for scalar attributes
33
32
  param.options.each do |option, value|
34
- validates full_key, option => value
33
+ validates full_key, option => value, allow_blank: !param.required?
35
34
  end
36
35
 
37
36
  # Add type-specific validations
@@ -40,6 +39,7 @@ module ApiRegulator
40
39
  validate -> { validate_string(full_key) } if param.type == :string
41
40
  end
42
41
 
42
+
43
43
  def define_object_validations(param, full_key)
44
44
  # Build nested validator class
45
45
  nested_validator_class = build_nested_validator_class(param.children, param.name, self)
@@ -104,17 +104,20 @@ module ApiRegulator
104
104
  # Instance methods
105
105
  def validate_array_of_objects(attribute, item_validator_class, param)
106
106
  raw_value = @raw_attributes[attribute]
107
+
108
+ # Ensure the presence check works only on the array itself, not its contents
107
109
  if raw_value.blank?
108
110
  errors.add(attribute, "can't be blank") if param.options[:presence]
109
111
  return
110
112
  end
113
+
111
114
  unless raw_value.is_a?(Array)
112
115
  errors.add(attribute, "must be an array")
113
116
  return
114
117
  end
115
118
 
116
119
  raw_value.each_with_index do |value, index|
117
- unless value.is_a?(Hash) || raw_value.is_a?(ActionController::Parameters)
120
+ unless value.is_a?(Hash) || value.is_a?(ActionController::Parameters)
118
121
  errors.add("#{attribute}[#{index}]", "must be a hash")
119
122
  next
120
123
  end
@@ -136,27 +139,45 @@ module ApiRegulator
136
139
  errors.add(attribute, "can't be blank") if param.options[:presence]
137
140
  return
138
141
  end
142
+
139
143
  unless raw_value.is_a?(Array)
140
144
  errors.add(attribute, "must be an array")
141
145
  return
142
146
  end
143
147
 
148
+ inclusion_list = param.options[:inclusion]&.dig(:in)
149
+
144
150
  raw_value.each_with_index do |value, index|
151
+ # Skip type and inclusion validation if nil is allowed and value is nil
152
+ if value.nil? && (inclusion_list&.include?(nil) || param.options[:allow_nil_items])
153
+ next
154
+ end
155
+
156
+ # Type validation for non-nil values
145
157
  case param.item_type
146
158
  when :string
147
159
  unless value.is_a?(String)
148
160
  errors.add("#{attribute}[#{index}]", "must be a string")
161
+ next
149
162
  end
150
163
  when :integer
151
164
  unless value.is_a?(Integer)
152
165
  errors.add("#{attribute}[#{index}]", "must be an integer")
166
+ next
153
167
  end
154
168
  when :boolean
155
169
  unless [true, false].include?(value)
156
170
  errors.add("#{attribute}[#{index}]", "must be a boolean")
171
+ next
157
172
  end
158
173
  else
159
174
  errors.add("#{attribute}[#{index}]", "has an unsupported type")
175
+ next
176
+ end
177
+
178
+ # Inclusion validation for non-nil values
179
+ if inclusion_list && !inclusion_list.include?(value)
180
+ errors.add("#{attribute}[#{index}]", "is not included in the list")
160
181
  end
161
182
  end
162
183
  end
@@ -164,6 +185,9 @@ module ApiRegulator
164
185
  def validate_nested_object(attribute, nested_validator_class, param)
165
186
  raw_value = @raw_attributes[attribute]
166
187
 
188
+ # Skip validation if optional and not present
189
+ return if raw_value.nil? && param.options[:optional]
190
+
167
191
  if raw_value.nil?
168
192
  errors.add(attribute, "can't be blank") if param.options[:presence]
169
193
  return
@@ -1,3 +1,3 @@
1
1
  module ApiRegulator
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-regulator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Massanek
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-14 00:00:00.000000000 Z
11
+ date: 2025-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -130,6 +130,7 @@ executables: []
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
+ - ".github/workflows/release.yml"
133
134
  - ".github/workflows/spec.yml"
134
135
  - ".gitignore"
135
136
  - ".rspec"