rails_validation_api 1.2.1 → 1.2.2
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/usage.rb +15 -14
- data/lib/rails_validation_api/validator.rb +18 -7
- data/lib/rails_validation_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4f6763bbc5879669935aedb9a4c25437da3a78c480ee2d0fd89a8c20ba52eec
|
4
|
+
data.tar.gz: d262f3175cb60f276c0f28b286fa2fcf3ccf294275943da75c6eb9e8b5dc8810
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0baf32fb6aca2cde5a15c874f5f46d69b3d7e3c0ab00f9f7cb51583359a70c454c2dc259bc981fd22dafe832c08758358d0659b6b4f881c3e8a58ca8a9ebe290
|
7
|
+
data.tar.gz: 737cf138b2137716889652e0155f9dd9905527a4bb3f439b9b0395201db551d01ed9e115eeb3d855d08d7cc30b76c81922b3c11e65f2a4030bc28864bf8bcf29
|
data/exe/commands/usage.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
puts <<~TEXT
|
2
|
-
-------------------------------------------------------------------------------------------------------------------------------------------------
|
3
|
-
| Add "include AutoLoadRailsValidationApi" to your controller ex: API::BaseController < ApplicationController to use the RailsValidationApi |
|
4
|
-
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
13
|
-
|
14
|
-
|
|
15
|
-
|
2
|
+
-------------------------------------------------------------------------------------------------------------------------------------------------
|
3
|
+
| Add "include AutoLoadRailsValidationApi" to your controller ex: API::BaseController < ApplicationController to use the RailsValidationApi |
|
4
|
+
| Add "config.autoload_paths += %w(\#{config.root}/app/validators/)" in config/application.rb to autoload validators. |
|
5
|
+
|-----------------------------------------------------------------------------------------------------------------------------------------------| |
|
6
|
+
| To use the RailsValidationApi, you need to add the following line to your Gemfile: |
|
7
|
+
| Usage: bundle exec rails_validation_api <command> [name] |
|
8
|
+
| Commands: |
|
9
|
+
| install Install the rails_validation_api gem. |
|
10
|
+
| generate <name> Generate a parameter validator and a validator for the specified name. |
|
11
|
+
| generate_parameter <name> Generate a parameter validator for the specified name. |
|
12
|
+
| destroy <name> Destroy the validator and parameter validator for the specified name. |
|
13
|
+
|------------------------------------------------------------------------------------------------------------------------------------------------
|
14
|
+
| Example: |
|
15
|
+
| bundle exec rails_validation_api generate purchaseorder |
|
16
|
+
|------------------------------------------------------------------------------------------------------------------------------------------------
|
16
17
|
TEXT
|
@@ -114,18 +114,19 @@ module RailsValidationApi
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def valid_type?(value, type)
|
117
|
-
|
118
|
-
|
117
|
+
value = format_string_to_int(value, type)
|
118
|
+
case type.to_s
|
119
|
+
when String.to_s
|
119
120
|
value.is_a?(String)
|
120
|
-
when Integer
|
121
|
+
when Integer.to_s
|
121
122
|
value.is_a?(Integer)
|
122
|
-
when Float
|
123
|
+
when Float.to_s
|
123
124
|
value.is_a?(Float) || value.is_a?(Integer)
|
124
|
-
when Hash
|
125
|
+
when Hash.to_s
|
125
126
|
value.is_a?(Hash)
|
126
|
-
when Array
|
127
|
+
when Array.to_s
|
127
128
|
value.is_a?(Array)
|
128
|
-
when TrueClass, FalseClass
|
129
|
+
when TrueClass.to_s, FalseClass.to_s
|
129
130
|
value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
130
131
|
else
|
131
132
|
value.is_a?(type)
|
@@ -157,5 +158,15 @@ module RailsValidationApi
|
|
157
158
|
@errors << { field: field, message: message }
|
158
159
|
end
|
159
160
|
end
|
161
|
+
|
162
|
+
def format_string_to_int(value, type)
|
163
|
+
return value unless value.is_a?(String)
|
164
|
+
|
165
|
+
return Integer(value) rescue value if type == Integer
|
166
|
+
return Float(value) rescue value if type == Float
|
167
|
+
value
|
168
|
+
rescue ArgumentError
|
169
|
+
value
|
170
|
+
end
|
160
171
|
end
|
161
172
|
end
|