rails_validation_api 1.0.0 → 1.2.1
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/exe/commands/generate_parameter_validator.rb +86 -0
- data/exe/commands/usage.rb +16 -0
- data/lib/rails_validation_api/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3aba9716be3690814ad64c4423454b33e674df5f1b46306c4a029ab8c18e58e2
|
4
|
+
data.tar.gz: f880f5c5f1238c1c2f84030698e9ff07a6403658155e7ae4d30fa0f2425e1fc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0cdaefd1e1c058ae02114353e562f5d7e3fdca4edb2c4c223934df2608701e453ab7c9e045b7167d3387011eac835a6f07a89967ed55a9ac78b07c3a8f14529
|
7
|
+
data.tar.gz: 4103a6c5597681e1ee4bb73f1a1f40afe7c3a91a3660c03340a27ec330098d81303d34856e4787e4c88e05568d084e150c970c3fbaf636ebfa9b8473e23d60ee
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module GenerateValidator
|
2
|
+
def generate_parameter_validator(name)
|
3
|
+
api = check_inflection(name)
|
4
|
+
class_name = "#{name.camelize}Validator"
|
5
|
+
path = "app/validators/api/validate_parameters/#{name}_validator.rb"
|
6
|
+
|
7
|
+
FileUtils.mkdir_p(File.dirname(path))
|
8
|
+
|
9
|
+
if File.exist?(path)
|
10
|
+
puts "⚠️ Validator already exists at #{path}"
|
11
|
+
else
|
12
|
+
File.write(path, <<~RUBY)
|
13
|
+
# frozen_string_literal: true
|
14
|
+
|
15
|
+
class #{api}::ValidateParameters::#{class_name}
|
16
|
+
FIELDS_VALIDATES = {
|
17
|
+
# account_id_validate:
|
18
|
+
# {
|
19
|
+
# field: :account_id, type: Integer, opts: [
|
20
|
+
# { required: true, message: "Account id is required" }
|
21
|
+
# ]
|
22
|
+
# }
|
23
|
+
}.freeze
|
24
|
+
|
25
|
+
def index
|
26
|
+
[
|
27
|
+
# FIELDS_VALIDATES[:account_id_validate]
|
28
|
+
]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
RUBY
|
32
|
+
|
33
|
+
puts "✅ Created #{path}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy_validator(name)
|
38
|
+
params_path = "app/validators/api/validate_parameters/#{name}_validator.rb"
|
39
|
+
path = "app/validators/api/#{name}_validator.rb"
|
40
|
+
|
41
|
+
if File.exist?(path)
|
42
|
+
File.delete(path)
|
43
|
+
puts "🗑️ Deleted #{path}"
|
44
|
+
else
|
45
|
+
puts "⚠️ File not found: #{path}"
|
46
|
+
end
|
47
|
+
if File.exist?(params_path)
|
48
|
+
File.delete(params_path)
|
49
|
+
puts "🗑️ Deleted #{params_path}"
|
50
|
+
else
|
51
|
+
puts "⚠️ File not found: #{params_path}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def generate_validator(name)
|
56
|
+
api = check_inflection(name)
|
57
|
+
class_name = "#{name.camelize}Validator"
|
58
|
+
path = "app/validators/api/#{name}_validator.rb"
|
59
|
+
|
60
|
+
FileUtils.mkdir_p(File.dirname(path))
|
61
|
+
|
62
|
+
if File.exist?(path)
|
63
|
+
puts "⚠️ Validator already exists at #{path}"
|
64
|
+
else
|
65
|
+
File.write(path, <<~RUBY)
|
66
|
+
# frozen_string_literal: true
|
67
|
+
|
68
|
+
class #{api}::#{class_name}
|
69
|
+
def initialize(model_name, account)
|
70
|
+
@model_name = model_name
|
71
|
+
@account = account
|
72
|
+
end
|
73
|
+
|
74
|
+
def index(opts)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
RUBY
|
78
|
+
|
79
|
+
puts "✅ Created #{path}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def usage
|
84
|
+
require_relative "./usage"
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
puts <<~TEXT
|
2
|
+
-------------------------------------------------------------------------------------------------------------------------------------------------
|
3
|
+
| Add "include AutoLoadRailsValidationApi" to your controller ex: API::BaseController < ApplicationController to use the RailsValidationApi |
|
4
|
+
|-----------------------------------------------------------------------------------------------------------------------------------------------| |
|
5
|
+
| To use the RailsValidationApi, you need to add the following line to your Gemfile: |
|
6
|
+
| Usage: bundle exec rails_validation_api <command> [name] |
|
7
|
+
| Commands: |
|
8
|
+
| install Install the rails_validation_api gem. |
|
9
|
+
| generate <name> Generate a parameter validator and a validator for the specified name. |
|
10
|
+
| generate_parameter <name> Generate a parameter validator for the specified name. |
|
11
|
+
| destroy <name> Destroy the validator and parameter validator for the specified name. |
|
12
|
+
|------------------------------------------------------------------------------------------------------------------------------------------------
|
13
|
+
| Example: |
|
14
|
+
| bundle exec rails_validation_api generate purchaseorder |
|
15
|
+
|------------------------------------------------------------------------------------------------------------------------------------------------
|
16
|
+
TEXT
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_validation_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Linh Nguyen Quang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-07-
|
11
|
+
date: 2025-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
|
-
description: Rails Validation API provides a powerful
|
83
|
+
description: Rails Validation API provides a powerful for validating request parameters
|
84
84
|
in Rails applications. Features include automatic validator loading based on controller/action
|
85
85
|
names, nested parameter validation, custom error handling, and seamless integration
|
86
86
|
with Rails controllers through concerns. Perfect for API applications requiring
|
@@ -92,6 +92,8 @@ executables:
|
|
92
92
|
extensions: []
|
93
93
|
extra_rdoc_files: []
|
94
94
|
files:
|
95
|
+
- exe/commands/generate_parameter_validator.rb
|
96
|
+
- exe/commands/usage.rb
|
95
97
|
- exe/rails_validation_api
|
96
98
|
- lib/auto_load_rails_validation_api.rb
|
97
99
|
- lib/rails_validation_api.rb
|