infer_model 0.1.2 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/.ruby-version +1 -1
- data/Gemfile.lock +30 -29
- data/lib/infer_model/parsers/date_time.rb +21 -0
- data/lib/infer_model/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0db6650dbf15131ccd40e479b1980e85754cd1055e862eede221cca10f3553e9
|
4
|
+
data.tar.gz: f6ec28401dda3153ea50a1eb1998d821958dfcf3d98c3f5f8f2160ef2322377b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea99ee69a52875475ba42929916904c9673ebd605332b0fec90cd8f00132c65956003e9a942babe677320535acb7aaa52c4a8bc42b1415e3060feb248ffda89e
|
7
|
+
data.tar.gz: 6cd11aefd834f5549281f58a705d23a9d14f61ce0907e6ed79a5633c35ffb34d5de2f4f593ab9b261d2a38815fc57d7e99c8a730656aa42c01a14e72774a9208
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.1
|
1
|
+
3.2.1
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
infer_model (0.1.
|
4
|
+
infer_model (0.1.5)
|
5
5
|
activesupport (~> 7.0)
|
6
6
|
dry-initializer (~> 3.0)
|
7
7
|
zeitwerk (~> 2.6)
|
@@ -9,68 +9,69 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (7.0.4)
|
12
|
+
activesupport (7.0.4.2)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 1.6, < 2)
|
15
15
|
minitest (>= 5.1)
|
16
16
|
tzinfo (~> 2.0)
|
17
17
|
ast (2.4.2)
|
18
18
|
coderay (1.1.3)
|
19
|
-
concurrent-ruby (1.
|
19
|
+
concurrent-ruby (1.2.0)
|
20
20
|
diff-lcs (1.5.0)
|
21
21
|
dotenv (2.8.1)
|
22
22
|
dry-initializer (3.1.1)
|
23
23
|
i18n (1.12.0)
|
24
24
|
concurrent-ruby (~> 1.0)
|
25
|
-
json (2.6.
|
25
|
+
json (2.6.3)
|
26
26
|
method_source (1.0.0)
|
27
|
-
minitest (5.
|
27
|
+
minitest (5.17.0)
|
28
28
|
parallel (1.22.1)
|
29
|
-
parser (3.
|
29
|
+
parser (3.2.1.0)
|
30
30
|
ast (~> 2.4.1)
|
31
|
-
pry (0.14.
|
31
|
+
pry (0.14.2)
|
32
32
|
coderay (~> 1.1)
|
33
33
|
method_source (~> 1.0)
|
34
34
|
rainbow (3.1.1)
|
35
35
|
rake (13.0.6)
|
36
|
-
regexp_parser (2.
|
36
|
+
regexp_parser (2.7.0)
|
37
37
|
rexml (3.2.5)
|
38
|
-
rspec (3.
|
39
|
-
rspec-core (~> 3.
|
40
|
-
rspec-expectations (~> 3.
|
41
|
-
rspec-mocks (~> 3.
|
42
|
-
rspec-core (3.
|
43
|
-
rspec-support (~> 3.
|
44
|
-
rspec-expectations (3.
|
38
|
+
rspec (3.12.0)
|
39
|
+
rspec-core (~> 3.12.0)
|
40
|
+
rspec-expectations (~> 3.12.0)
|
41
|
+
rspec-mocks (~> 3.12.0)
|
42
|
+
rspec-core (3.12.1)
|
43
|
+
rspec-support (~> 3.12.0)
|
44
|
+
rspec-expectations (3.12.2)
|
45
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.
|
47
|
-
rspec-mocks (3.
|
46
|
+
rspec-support (~> 3.12.0)
|
47
|
+
rspec-mocks (3.12.3)
|
48
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
-
rspec-support (~> 3.
|
50
|
-
rspec-support (3.
|
51
|
-
rubocop (1.
|
49
|
+
rspec-support (~> 3.12.0)
|
50
|
+
rspec-support (3.12.0)
|
51
|
+
rubocop (1.45.1)
|
52
52
|
json (~> 2.3)
|
53
53
|
parallel (~> 1.10)
|
54
|
-
parser (>= 3.
|
54
|
+
parser (>= 3.2.0.0)
|
55
55
|
rainbow (>= 2.2.2, < 4.0)
|
56
56
|
regexp_parser (>= 1.8, < 3.0)
|
57
57
|
rexml (>= 3.2.5, < 4.0)
|
58
|
-
rubocop-ast (>= 1.
|
58
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
59
59
|
ruby-progressbar (~> 1.7)
|
60
|
-
unicode-display_width (>=
|
61
|
-
rubocop-ast (1.
|
62
|
-
parser (>= 3.
|
63
|
-
rubocop-performance (1.
|
60
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
61
|
+
rubocop-ast (1.26.0)
|
62
|
+
parser (>= 3.2.1.0)
|
63
|
+
rubocop-performance (1.16.0)
|
64
64
|
rubocop (>= 1.7.0, < 2.0)
|
65
65
|
rubocop-ast (>= 0.4.0)
|
66
66
|
ruby-progressbar (1.11.0)
|
67
|
-
tzinfo (2.0.
|
67
|
+
tzinfo (2.0.6)
|
68
68
|
concurrent-ruby (~> 1.0)
|
69
|
-
unicode-display_width (2.2
|
70
|
-
zeitwerk (2.6.
|
69
|
+
unicode-display_width (2.4.2)
|
70
|
+
zeitwerk (2.6.7)
|
71
71
|
|
72
72
|
PLATFORMS
|
73
73
|
arm64-darwin-21
|
74
|
+
arm64-darwin-22
|
74
75
|
x86_64-linux
|
75
76
|
|
76
77
|
DEPENDENCIES
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_support"
|
3
4
|
require "date"
|
4
5
|
|
5
6
|
module InferModel
|
@@ -22,11 +23,31 @@ module InferModel
|
|
22
23
|
|
23
24
|
param :value
|
24
25
|
option :allow_blank, default: -> { true }
|
26
|
+
option :time_zone_offset, optional: true
|
27
|
+
option :time_zone, optional: true
|
25
28
|
|
26
29
|
def call
|
27
30
|
raise Parsers::Error, "value was blank which is not allowed" if value.nil? && !allow_blank
|
28
31
|
return if value.nil? || value.empty?
|
29
32
|
|
33
|
+
# make sure value parsed once before applying time zone
|
34
|
+
# so formats are validated
|
35
|
+
apply_time_zone(parsed_datetime)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def apply_time_zone(datetime)
|
41
|
+
if time_zone_offset
|
42
|
+
datetime.change(offset: time_zone_offset)
|
43
|
+
elsif time_zone
|
44
|
+
Time.use_zone(time_zone) { Time.zone.parse(value) } # discard parsed result and parse again in assumed zone
|
45
|
+
else
|
46
|
+
datetime
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def parsed_datetime
|
30
51
|
ACCEPTABLE_DATETIME_FORMATS.each do |format|
|
31
52
|
return DateTime.strptime(value, format)
|
32
53
|
rescue Date::Error
|
data/lib/infer_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infer_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay Schneider
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
201
|
- !ruby/object:Gem::Version
|
202
202
|
version: '0'
|
203
203
|
requirements: []
|
204
|
-
rubygems_version: 3.
|
204
|
+
rubygems_version: 3.4.6
|
205
205
|
signing_key:
|
206
206
|
specification_version: 4
|
207
207
|
summary: Infer data types from external sources to create a rails model for example
|