eitil 0.3.3 → 0.3.4
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/config/initializers/wrappers/scopes/default_scopes.rb +57 -61
- data/lib/eitil/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: f35510328554ac09ddfb48b697e0b7dd2b6a801b20954505b14849c2f1a3227a
|
4
|
+
data.tar.gz: 9d8edf28b695b3835d4dacaf46bd1dbe7dc1e9ebcd9ae2bce403b9a12ffe7529
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cec6226350e58696fb8d814d9cd7e57b768a39c5bc392d6686792d80ecc2dab328a64c131ce32bf05d49627f30b10606544e3c1a6170c4e6941054649dd931d
|
7
|
+
data.tar.gz: cbb2ad53d5727feffad6007bde83d34edaf4336f47330ad95f096348f423fc0d3fca02375a3d34c38f420f9df99d30ec0f713b2436b62488879594a5e4e9bee3
|
@@ -2,86 +2,82 @@ module Eitil
|
|
2
2
|
module DefaultScopes
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
included do
|
5
|
-
|
6
|
-
SharableDateScopes = -> (column) {
|
7
|
-
eitil_scope :"#{column}_today", -> { where("#{column} = ?", Date.today) }
|
8
|
-
eitil_scope :"#{column}_past", -> { where("#{column} < ?", Date.today) }
|
9
|
-
eitil_scope :"#{column}_future", -> { where("#{column} > ?", Date.today) }
|
10
|
-
|
11
|
-
eitil_scope :"#{column}_on_date", -> (date) { where("#{column} = ?", date) }
|
12
|
-
eitil_scope :"#{column}_before_date", -> (date) { where("#{column} = ?", date) }
|
13
|
-
eitil_scope :"#{column}_after_date", -> (date) { where("#{column} = ?", date) }
|
14
|
-
eitil_scope :"#{column}_between_dates", -> (from, till) { where("#{column} >= ? and #{column} <= ?", from, till) }
|
5
|
+
class << self
|
15
6
|
|
16
|
-
|
17
|
-
|
18
|
-
|
7
|
+
SharableDateScopes = -> (_class, column) {
|
8
|
+
_class.eitil_scope :"#{column}_today", -> { where("#{column} = ?", Date.today) }
|
9
|
+
_class.eitil_scope :"#{column}_past", -> { where("#{column} < ?", Date.today) }
|
10
|
+
_class.eitil_scope :"#{column}_future", -> { where("#{column} > ?", Date.today) }
|
11
|
+
|
12
|
+
_class.eitil_scope :"#{column}_on_date", -> (date) { where("#{column} = ?", date) }
|
13
|
+
_class.eitil_scope :"#{column}_before_date", -> (date) { where("#{column} = ?", date) }
|
14
|
+
_class.eitil_scope :"#{column}_after_date", -> (date) { where("#{column} = ?", date) }
|
15
|
+
_class.eitil_scope :"#{column}_between_dates", -> (from, till) { where("#{column} >= ? and #{column} <= ?", from, till) }
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
eitil_scope :"#{column}_higher_than", -> (number) { where("#{column} = >", number) }
|
24
|
-
eitil_scope :"#{column}_between", -> (min, max) { where("#{column} >= ? and #{column} <= ?", min, max) }
|
17
|
+
_class.eitil_scope :"#{column}_oldest_first", -> { order("#{column} ASC") }
|
18
|
+
_class.eitil_scope :"#{column}_newest_first", -> { order("#{column} DESC") }
|
19
|
+
}
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
SharableNumScopes = -> (_class, column) {
|
22
|
+
_class.eitil_scope :"#{column}_equal_to", -> (number) { where("#{column} = ?", number) }
|
23
|
+
_class.eitil_scope :"#{column}_lower_than", -> (number) { where("#{column} = <", number) }
|
24
|
+
_class.eitil_scope :"#{column}_higher_than", -> (number) { where("#{column} = >", number) }
|
25
|
+
_class.eitil_scope :"#{column}_between", -> (min, max) { where("#{column} >= ? and #{column} <= ?", min, max) }
|
29
26
|
|
30
|
-
|
27
|
+
_class.eitil_scope :"#{column}_ascending", -> { order("#{column} ASC") }
|
28
|
+
_class.eitil_scope :"#{column}_descending", -> { order("#{column} DESC") }
|
29
|
+
}
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
super
|
37
|
-
end
|
31
|
+
def inherited(subclass)
|
32
|
+
super
|
33
|
+
subclass.use_eitil_scopes
|
34
|
+
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
def use_eitil_scopes
|
37
|
+
return if abstract_class?
|
38
|
+
%i[boolean datetime date integer float].each { |_type| send :"create_eitil_#{_type}_scopes" }
|
39
|
+
end
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
41
|
+
def eitil_scope(_name, _proc)
|
42
|
+
scope _name, _proc unless respond_to? _name
|
43
|
+
end
|
44
|
+
|
45
|
+
def columns_of_type(data_type)
|
46
|
+
columns_hash.select { |column,v| v.sql_type_metadata.type == data_type }
|
47
|
+
end
|
51
48
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
def create_eitil_boolean_scopes
|
50
|
+
columns_of_type(:boolean)&.map do |column, object|
|
51
|
+
eitil_scope :"#{column}_true", -> { where(column => true) }
|
52
|
+
eitil_scope :"#{column}_false", -> { where(column => [false, nil]) }
|
53
|
+
end
|
56
54
|
end
|
57
|
-
end
|
58
55
|
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
def create_eitil_datetime_scopes
|
57
|
+
columns_of_type(:datetime)&.map do |column, object|
|
58
|
+
SharableDateScopes.call self, column
|
59
|
+
end
|
62
60
|
end
|
63
|
-
end
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
def create_eitil_date_scopes
|
63
|
+
columns_of_type(:date)&.map do |column, object|
|
64
|
+
SharableDateScopes.call self, column
|
65
|
+
end
|
68
66
|
end
|
69
|
-
end
|
70
67
|
|
71
|
-
|
72
|
-
|
73
|
-
|
68
|
+
def create_eitil_integer_scopes
|
69
|
+
columns_of_type(:integer)&.map do |column, object|
|
70
|
+
SharableNumScopes.call self, column
|
71
|
+
end
|
74
72
|
end
|
75
|
-
end
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
|
74
|
+
def create_eitil_float_scopes
|
75
|
+
columns_of_type(:float)&.map do |column, object|
|
76
|
+
SharableNumScopes.call self, column
|
77
|
+
end
|
80
78
|
end
|
81
|
-
end
|
82
79
|
|
83
80
|
end
|
84
|
-
|
85
81
|
end
|
86
82
|
end
|
87
83
|
end
|
data/lib/eitil/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eitil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jurriaan Schrofer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|