eitil 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7472becb49f3ad8ed37b1af23436257255cd050fd6d101a552fad3b35d020e38
4
- data.tar.gz: 3508a76cd84733740cc9b8e9be223406ec4f620f38d9ba86048118743c058dd5
3
+ metadata.gz: f35510328554ac09ddfb48b697e0b7dd2b6a801b20954505b14849c2f1a3227a
4
+ data.tar.gz: 9d8edf28b695b3835d4dacaf46bd1dbe7dc1e9ebcd9ae2bce403b9a12ffe7529
5
5
  SHA512:
6
- metadata.gz: 52c7c51884686864b8b1aede6fc70a03028636614ef309ef59f9a70336091bd1e122ca2e7ccd99dcd824e371c60a83db73924cda249c373fda62b6f548af32fd
7
- data.tar.gz: 47071fee4cd78efdda04753406985bb093150b70e4d1bcfd355091f3c402cd08603a508c234e3dec2d9d324c1e2a23f0f86c2ae33d1bd914b0c5f1d3631d0de6
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
- eitil_scope :"#{column}_oldest_first", -> { order("#{column} ASC") }
17
- eitil_scope :"#{column}_newest_first", -> { order("#{column} DESC") }
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
- SharableNumScopes = -> (column) {
21
- eitil_scope :"#{column}_equal_to", -> (number) { where("#{column} = ?", number) }
22
- eitil_scope :"#{column}_lower_than", -> (number) { where("#{column} = <", number) }
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
- eitil_scope :"#{column}_ascending", -> { order("#{column} ASC") }
27
- eitil_scope :"#{column}_descending", -> { order("#{column} DESC") }
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
- class << self
27
+ _class.eitil_scope :"#{column}_ascending", -> { order("#{column} ASC") }
28
+ _class.eitil_scope :"#{column}_descending", -> { order("#{column} DESC") }
29
+ }
31
30
 
32
- private
33
-
34
- def self.inherited(subclass)
35
- use_eitil_scopes
36
- super
37
- end
31
+ def inherited(subclass)
32
+ super
33
+ subclass.use_eitil_scopes
34
+ end
38
35
 
39
- def use_eitil_scopes
40
- return if abstract_class?
41
- %i[boolean datetime date integer float].each { |_type| send :"create_eitil_#{_type}_scopes" }
42
- end
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
- def eitil_scope(_name, _proc)
45
- scope _name, _proc unless respond_to? _name
46
- end
47
-
48
- def columns_of_type(data_type)
49
- columns_hash.select { |column,v| v.sql_type_metadata.type == data_type }
50
- end
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
- def create_eitil_boolean_scopes
53
- columns_of_type(:boolean)&.map do |column, object|
54
- eitil_scope :"#{column}_true", -> { where(column => true) }
55
- eitil_scope :"#{column}_false", -> { where(column => [false, nil]) }
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
- def create_eitil_datetime_scopes
60
- columns_of_type(:datetime)&.map do |column, object|
61
- SharableDateScopes.call column
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
- def create_eitil_date_scopes
66
- columns_of_type(:date)&.map do |column, object|
67
- SharableDateScopes.call column
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
- def create_eitil_integer_scopes
72
- columns_of_type(:integer)&.map do |column, object|
73
- SharableNumScopes.call column
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
- def create_eitil_float_scopes
78
- columns_of_type(:float)&.map do |column, object|
79
- SharableNumScopes.call column
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
@@ -1,3 +1,3 @@
1
1
  module Eitil
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.4'
3
3
  end
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.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-18 00:00:00.000000000 Z
11
+ date: 2021-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails