eitil 1.1.19 → 1.1.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/eitil_core/lib/eitil_core/application_record/all_associations.rb +2 -0
- data/eitil_core/lib/eitil_core/application_record/duck_find.rb +2 -0
- data/eitil_core/lib/eitil_core/application_record/find_by_like.rb +2 -0
- data/eitil_core/lib/eitil_core/application_record/model_atts.rb +2 -0
- data/eitil_core/lib/eitil_core/application_record/where_like.rb +2 -0
- data/eitil_wrapper/README.md +28 -0
- data/eitil_wrapper/lib/eitil_wrapper.rb +1 -0
- data/eitil_wrapper/lib/eitil_wrapper/callbacks.rb +2 -0
- data/eitil_wrapper/lib/eitil_wrapper/callbacks/helper_methods.rb +109 -0
- data/eitil_wrapper/lib/eitil_wrapper/railtie.rb +3 -0
- data/eitil_wrapper/lib/eitil_wrapper/scopes/default_scopes.rb +2 -0
- data/lib/eitil/railtie.rb +1 -0
- data/lib/eitil/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 276d6270d8b18ac77d7ca5eb64524c4a7e00eb7155137d4fe88e5aaa4ef26811
|
4
|
+
data.tar.gz: 5e4a1db5aa4244dc7b9a5179438ed16d0a4fdc75686642511d2cf8c6d094cbec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b75dd17f605fe1e8205cf0b412eb82e8f3a618a2516c213172beaec0c46f5a7a49f1e1ea71a5f8ba9479d0c3712bc3c52981c76b072d015270a69407f1df09af
|
7
|
+
data.tar.gz: b722f1234987f762693afd2e3f92e7ed67b31fbfa4f27cca8583c6999876065a1863d6b66b2e9ad6b548d93af7af033a6ee84c11856154ecfb7954d32a79b19c
|
data/eitil_wrapper/README.md
CHANGED
@@ -9,6 +9,34 @@ EitilWrapper wraps core rails operations with extended utilities – such as rou
|
|
9
9
|
|
10
10
|
|
11
11
|
|
12
|
+
|
13
|
+
## EitilWrapper::Callbacks
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
|
17
|
+
require "eitil_wrapper/callbacks"
|
18
|
+
|
19
|
+
```
|
20
|
+
|
21
|
+
Callback helper methods are created for use within a model's callbacks. You can use them as callback conditionals, e.g. "after_save :do_this, if :doing_became_true". Which scopes are generated depends on the datatype of a column. The methods currently generated are:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# require "eitil_wrapper/callbacks/helper_methods"
|
25
|
+
|
26
|
+
# columns of datatype: boolean
|
27
|
+
.{column_name}_became_true
|
28
|
+
.{column_name}_becomes_true
|
29
|
+
.{column_name}_to_true # works for both become and became
|
30
|
+
|
31
|
+
.{column_name}_became_false
|
32
|
+
.{column_name}_becomes_false
|
33
|
+
.{column_name}_to_false # works for both become and became
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
12
40
|
## EitilWrapper::Decorators
|
13
41
|
|
14
42
|
```ruby
|
@@ -0,0 +1,109 @@
|
|
1
|
+
|
2
|
+
# require "eitil_wrapper/callbacks/helper_methods"
|
3
|
+
|
4
|
+
# require "eitil_wrapper/railtie" to run the dynamic dispatch as an init hook during boot
|
5
|
+
require "eitil_wrapper/railtie"
|
6
|
+
|
7
|
+
require "eitil_core/argument_helpers/all_args_to_ivars"
|
8
|
+
|
9
|
+
module EitilWrapper
|
10
|
+
module Callbacks
|
11
|
+
module HelperMethods
|
12
|
+
|
13
|
+
Eitil::ApplicationRecordModules << self
|
14
|
+
|
15
|
+
def inherited(subclass)
|
16
|
+
super
|
17
|
+
subclass.use_eitil_callback_helper_methods
|
18
|
+
|
19
|
+
rescue => e
|
20
|
+
puts "callback helper methods failed for #{subclass} because of #{e.class} and '#{e.to_s.split(' ').first}'"
|
21
|
+
end
|
22
|
+
|
23
|
+
def use_eitil_callback_helper_methods
|
24
|
+
return if abstract_class?
|
25
|
+
create_eitil_boolean_callback_helper_methods
|
26
|
+
end
|
27
|
+
|
28
|
+
def columns_of_type(data_type)
|
29
|
+
columns_hash.select { |column,v| v.sql_type_metadata.type == data_type }
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_eitil_boolean_callback_helper_methods
|
33
|
+
columns = columns_of_type :boolean
|
34
|
+
columns&.each do |column_name, eitil_object|
|
35
|
+
|
36
|
+
# truthy methods
|
37
|
+
create_eitil_became_true_callback_helper column_name
|
38
|
+
create_eitil_becomes_true_callback_helper column_name
|
39
|
+
create_eitil_to_true_callback_helper column_name
|
40
|
+
|
41
|
+
# falsy methods
|
42
|
+
create_eitil_became_false_callback_helper column_name
|
43
|
+
create_eitil_becomes_false_callback_helper column_name
|
44
|
+
create_eitil_to_false_callback_helper column_name
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_eitil_became_true_callback_helper(column_name)
|
50
|
+
method_name = "#{column_name}_became_true"
|
51
|
+
|
52
|
+
define_method(method_name) do
|
53
|
+
_changes = previous_changes[column_name]
|
54
|
+
_changes && !_changes[0] && _changes[1]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_eitil_becomes_true_callback_helper(column_name)
|
59
|
+
method_name = "#{column_name}_becomes_true"
|
60
|
+
|
61
|
+
define_method(method_name) do
|
62
|
+
_changes = changes[column_name]
|
63
|
+
_changes && !_changes[0] && _changes[1]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_eitil_to_true_callback_helper(column_name)
|
68
|
+
method_name = "#{column_name}_to_true"
|
69
|
+
becomes_method = "#{column_name}_becomes_true"
|
70
|
+
became_method = "#{column_name}_became_true"
|
71
|
+
|
72
|
+
define_method(method_name) do
|
73
|
+
# changes are present in before_safe, otherwise dispatch to after_save
|
74
|
+
changes&.present? ? send(becomes_method) : send(became_method)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def create_eitil_became_false_callback_helper(column_name)
|
79
|
+
method_name = "#{column_name}_became_false"
|
80
|
+
|
81
|
+
define_method(method_name) do
|
82
|
+
_changes = previous_changes[column_name]
|
83
|
+
_changes && _changes[0] && !_changes[1]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def create_eitil_becomes_false_callback_helper(column_name)
|
88
|
+
method_name = "#{column_name}_becomes_false"
|
89
|
+
|
90
|
+
define_method(method_name) do
|
91
|
+
_changes = changes[column_name]
|
92
|
+
_changes && _changes[0] && !_changes[1]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def create_eitil_to_false_callback_helper(column_name)
|
97
|
+
method_name = "#{column_name}_to_false"
|
98
|
+
becomes_method = "#{column_name}_becomes_false"
|
99
|
+
became_method = "#{column_name}_became_false"
|
100
|
+
|
101
|
+
define_method(method_name) do
|
102
|
+
# changes are present in before_safe, otherwise dispatch to after_save
|
103
|
+
changes&.present? ? send(becomes_method) : send(became_method)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -12,6 +12,9 @@ module EitilWrapper
|
|
12
12
|
::ApplicationRecord.send(:extend, EitilWrapper::Scopes::DefaultScopes)
|
13
13
|
end
|
14
14
|
|
15
|
+
if Object.const_defined?('EitilWrapper::Callbacks::HelperMethods')
|
16
|
+
::ApplicationRecord.send(:extend, EitilWrapper::Callbacks::HelperMethods)
|
17
|
+
end
|
15
18
|
|
16
19
|
if Object.const_defined?('EitilWrapper::CreateSingleMethodJob')
|
17
20
|
|
@@ -8,6 +8,8 @@ module EitilWrapper
|
|
8
8
|
module Scopes
|
9
9
|
module DefaultScopes
|
10
10
|
|
11
|
+
Eitil::ApplicationRecordModules << self
|
12
|
+
|
11
13
|
SharableDateScopes = -> (_class, column) {
|
12
14
|
_class.eitil_scope :"#{column}_today", -> { where("#{column} = ?", Date.today) }
|
13
15
|
_class.eitil_scope :"#{column}_past", -> { where("#{column} < ?", Date.today) }
|
data/lib/eitil/railtie.rb
CHANGED
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: 1.1.
|
4
|
+
version: 1.1.20
|
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-
|
11
|
+
date: 2021-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -179,6 +179,8 @@ files:
|
|
179
179
|
- eitil_support/lib/eitil_support/stacktrace/stack.rb
|
180
180
|
- eitil_wrapper/README.md
|
181
181
|
- eitil_wrapper/lib/eitil_wrapper.rb
|
182
|
+
- eitil_wrapper/lib/eitil_wrapper/callbacks.rb
|
183
|
+
- eitil_wrapper/lib/eitil_wrapper/callbacks/helper_methods.rb
|
182
184
|
- eitil_wrapper/lib/eitil_wrapper/decorators.rb
|
183
185
|
- eitil_wrapper/lib/eitil_wrapper/decorators/application_decorator.rb
|
184
186
|
- eitil_wrapper/lib/eitil_wrapper/decorators/controller_decorator.rb
|