lucky_param 0.1.1 → 0.1.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/lib/lucky_param/checker.rb +10 -3
- data/lib/lucky_param/version.rb +1 -1
- data/lib/lucky_param.rb +11 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74c92c60d88a3b80c6dcf648a3eebcd94867d9c3f332c383a59b034e53d0ab10
|
4
|
+
data.tar.gz: 598848e0d283df5c34089c9e497073b33891ae7b0b40e5555527e2809b10da5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fac2010cc62e11ed9696977ee2f40518d185408de28f8ddb40c024eeea82532d3f9e1e828924fd6c045d9094e345f6a4c4f9eba180d377bb20bfa60e2274a8c
|
7
|
+
data.tar.gz: 9573ff399451714f7d9742fe2772b102feb1073182f911ce265172b5a41d712197c53136d0ecaab0aefd4a685991b45c1848b71d57f481f2432a1011d9c83f0e
|
data/lib/lucky_param/checker.rb
CHANGED
@@ -6,17 +6,24 @@ module LuckyParam
|
|
6
6
|
->(_obj) { true }
|
7
7
|
],
|
8
8
|
String: [
|
9
|
-
->(obj) {
|
9
|
+
->(obj) { obj.is_a?(String) },
|
10
10
|
"must be valid String"
|
11
11
|
],
|
12
|
+
Boolean: [
|
13
|
+
->(obj) { %w[true false 1 0].include?(obj.to_s) },
|
14
|
+
"must be one of [true false 1 0]"
|
15
|
+
],
|
12
16
|
Integer: [
|
13
|
-
->(obj) { obj.
|
17
|
+
->(obj) { obj.to_s =~ /\A(0|[1-9]\d*)\Z$/ },
|
14
18
|
"must be valid Integer"
|
15
19
|
],
|
16
20
|
Float: [
|
17
|
-
->(obj) { obj.
|
21
|
+
->(obj) { obj.to_s =~ /\A^[-+]?[0-9]+([,.][0-9]+)?\Z$/ },
|
18
22
|
"must be valid Float"
|
19
23
|
],
|
24
|
+
Number: [
|
25
|
+
->(obj) { Float(obj) rescue false }
|
26
|
+
],
|
20
27
|
Email: [
|
21
28
|
->(obj) { obj =~ /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/ },
|
22
29
|
"must be valid Email"
|
data/lib/lucky_param/version.rb
CHANGED
data/lib/lucky_param.rb
CHANGED
@@ -1,39 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_support/core_ext/object/blank"
|
4
|
+
|
3
5
|
require_relative "./lucky_param/version"
|
4
6
|
require_relative "./lucky_param/checker"
|
5
7
|
|
6
8
|
module LuckyParam
|
7
|
-
class ParamMissError < StandardError
|
8
|
-
end
|
9
|
-
|
10
|
-
class ParamFormatError < StandardError
|
11
|
-
end
|
12
|
-
|
13
|
-
class UnknownCheckerError < StandardError
|
14
|
-
end
|
9
|
+
class ParamMissError < StandardError; end
|
10
|
+
class ParamFormatError < StandardError; end
|
11
|
+
class UnknownCheckerError < StandardError; end
|
15
12
|
|
16
13
|
def required(column, checker_type)
|
17
|
-
|
14
|
+
raise ParamMissError.new("Missing Params: #{column}") if params[column].blank?
|
15
|
+
message = checker_message(column, checker_type)
|
16
|
+
raise ParamFormatError.new("Wrong Params Format: #{message}") if message
|
18
17
|
end
|
19
18
|
|
20
19
|
def optional(column, checker_type)
|
21
|
-
|
20
|
+
return if params[column].blank?
|
21
|
+
message = checker_message(column, checker_type)
|
22
|
+
raise ParamFormatError.new("Wrong Params Format: #{message}") if message
|
22
23
|
end
|
23
24
|
|
24
25
|
private
|
25
26
|
|
26
|
-
def required_optional(type, column, checker_type)
|
27
|
-
unless params[column]
|
28
|
-
return if type == :optional
|
29
|
-
raise ParamMissError, "Missing Params: #{column}"
|
30
|
-
end
|
31
|
-
message = checker_message(column, checker_type)
|
32
|
-
if message
|
33
|
-
raise ParamFormatError, "Wrong Params Format: #{message}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
27
|
def checker_message(column, checker_type)
|
38
28
|
checker = CUSTOM_CHECKER[checker_type] if LuckyParam.const_defined?(:CUSTOM_CHECKER)
|
39
29
|
checker ||= CHECKER.fetch(checker_type) {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lucky_param
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shooting Fly
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|