istox 0.1.98 → 0.1.100
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/Gemfile.lock +1 -1
- data/lib/istox/helpers/common_helper.rb +4 -0
- data/lib/istox/helpers/result_handler.rb +15 -7
- data/lib/istox/version.rb +1 -1
- 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: 2485877c8909c883204a97adf7363c3c7a4448b2f6f8f1c057034164c9ffa0e3
|
|
4
|
+
data.tar.gz: 4f8a5c0c01e8023f52b0d14bf5022b04ed4d475919e9c1f0a81510e78e15948b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a113bf5ada59c04108ebd95c46b4d60bf24bbaa4f864dde10bf1a99c0c61d90e5ea528b163260bf074c2d684553ed60c7acb4d0319859ecf4edd00708c463b21
|
|
7
|
+
data.tar.gz: 86b2a11cc400ee880e0cf80c980f747a38928fbb400db37437fa4436eb993ac970da45c7351b9b1a91f5d217af808547d8c75996c3e771d1e0caed58f6ec5d79
|
data/Gemfile.lock
CHANGED
|
@@ -13,6 +13,10 @@ module Istox
|
|
|
13
13
|
is_numeric ? Time.at(input.to_i).to_datetime : Time.parse(input)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
def self.to_boolean(input)
|
|
17
|
+
!(input.blank? || input.to_s.downcase == 'false' || input.to_s.downcase == '0')
|
|
18
|
+
end
|
|
19
|
+
|
|
16
20
|
def self.to_open_struct(model)
|
|
17
21
|
return nil if model.blank?
|
|
18
22
|
|
|
@@ -5,6 +5,9 @@ module Istox
|
|
|
5
5
|
query = filter(query: query, meta: meta) unless exclude_filter
|
|
6
6
|
query = order(query: query, meta: meta) unless exclude_order
|
|
7
7
|
|
|
8
|
+
# if never set limit, means no pagination is needed
|
|
9
|
+
return OpenStruct.new(data: query.all, pagination: nil) if meta.limit.blank? || meta.limit.zero?
|
|
10
|
+
|
|
8
11
|
return paginate(query: query, meta: meta) unless exclude_paginate
|
|
9
12
|
|
|
10
13
|
query
|
|
@@ -15,7 +18,8 @@ module Istox
|
|
|
15
18
|
|
|
16
19
|
meta.filters.each do |filter|
|
|
17
20
|
# chain the query with AND conditions
|
|
18
|
-
if
|
|
21
|
+
# skip if there is no compare present, mean it is for inner filters
|
|
22
|
+
if filter.compare.present?
|
|
19
23
|
validate_filter(filter)
|
|
20
24
|
query = query.where("#{filter.field} #{transform_compare(filter.type, filter.compare)} ?",
|
|
21
25
|
transform_value(filter.type, filter.value))
|
|
@@ -23,7 +27,7 @@ module Istox
|
|
|
23
27
|
|
|
24
28
|
next if filter.filters.blank?
|
|
25
29
|
|
|
26
|
-
# contains inner filters, chain the query with OR
|
|
30
|
+
# contains inner filters, chain the query with AND condition but internally with OR condition
|
|
27
31
|
columns = []
|
|
28
32
|
values = []
|
|
29
33
|
filter.filters.each do |inner_filter|
|
|
@@ -66,11 +70,11 @@ module Istox
|
|
|
66
70
|
pagination: OpenStruct.new(
|
|
67
71
|
page: current_page,
|
|
68
72
|
limit: meta.limit,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
previousPage: current_page - 1,
|
|
74
|
+
currentPage: current_page,
|
|
75
|
+
nextPage: current_page < page_count ? current_page + 1 : 0,
|
|
76
|
+
pageCount: page_count,
|
|
77
|
+
totalCount: total
|
|
74
78
|
)
|
|
75
79
|
)
|
|
76
80
|
end
|
|
@@ -108,7 +112,9 @@ module Istox
|
|
|
108
112
|
compare
|
|
109
113
|
end
|
|
110
114
|
|
|
115
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
|
111
116
|
def self.transform_value(type, value)
|
|
117
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
|
112
118
|
return value if value.blank? || type.blank? || type.downcase == 'string'
|
|
113
119
|
|
|
114
120
|
return 'NULL' if type.downcase == 'nullable' && %w[null true yes].include?(type.downcase)
|
|
@@ -119,6 +125,8 @@ module Istox
|
|
|
119
125
|
|
|
120
126
|
return value.to_f if type.downcase == 'float'
|
|
121
127
|
|
|
128
|
+
return ::Istox::CommonHelper.to_boolean(value) if type.downcase == 'boolean'
|
|
129
|
+
|
|
122
130
|
return ::Istox::CommonHelper.to_datetime(value) if type.downcase == 'date' || type.downcase == 'datetime'
|
|
123
131
|
end
|
|
124
132
|
|
data/lib/istox/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: istox
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.100
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Siong Leng
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-12-
|
|
11
|
+
date: 2019-12-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bunny
|