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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7020160e13bd3a44d267c4276583f909457fbabf4773c50c8333c0d75f12691b
4
- data.tar.gz: 2b6f3221afaf89a16060062e9be81fdfd87508b8e2ee3ab249f648f0c92ad8b5
3
+ metadata.gz: 276d6270d8b18ac77d7ca5eb64524c4a7e00eb7155137d4fe88e5aaa4ef26811
4
+ data.tar.gz: 5e4a1db5aa4244dc7b9a5179438ed16d0a4fdc75686642511d2cf8c6d094cbec
5
5
  SHA512:
6
- metadata.gz: ce8f3a2018d4cf475901a1da877888d45def474dda77510cb63d8f25ae1bbbb9c441e325f32cda7305806abf61201a4e9dccf6921d2adb631ce4f25fc9d83625
7
- data.tar.gz: f887dac92a3bc705a09717587880c33840046d70145434ce1e2debbff340aaa7104a3ff14bda824059f6c84a04df8c54af1581728367c365d6ef83d6ad4f8ad7
6
+ metadata.gz: b75dd17f605fe1e8205cf0b412eb82e8f3a618a2516c213172beaec0c46f5a7a49f1e1ea71a5f8ba9479d0c3712bc3c52981c76b072d015270a69407f1df09af
7
+ data.tar.gz: b722f1234987f762693afd2e3f92e7ed67b31fbfa4f27cca8583c6999876065a1863d6b66b2e9ad6b548d93af7af033a6ee84c11856154ecfb7954d32a79b19c
@@ -8,6 +8,8 @@ module EitilCore
8
8
  module ApplicationRecord
9
9
  module AllAssociations
10
10
 
11
+ Eitil::ApplicationRecordModules << self
12
+
11
13
  def all_associations
12
14
  reflect_on_all_associations.map do |assoc|
13
15
  { assoc.name => assoc.association_class.to_s.demodulize }
@@ -8,6 +8,8 @@ module EitilCore
8
8
  module ApplicationRecord
9
9
  module DuckFind
10
10
 
11
+ Eitil::ApplicationRecordModules << self
12
+
11
13
  def duck_find(identifier)
12
14
 
13
15
  case identifier
@@ -8,6 +8,8 @@ module EitilCore
8
8
  module ApplicationRecord
9
9
  module FindByLike
10
10
 
11
+ Eitil::ApplicationRecordModules << self
12
+
11
13
  def find_by_like(_hash)
12
14
  column, like = _hash.first
13
15
  find_by("LOWER(#{column}) LIKE ?", "%#{like.downcase}%")
@@ -8,6 +8,8 @@ module EitilCore
8
8
  module ApplicationRecord
9
9
  module ModelAtts
10
10
 
11
+ Eitil::ApplicationRecordModules << self
12
+
11
13
  def model_atts
12
14
  columns = self.columns_hash.keys.map(&:to_sym)
13
15
  reject = %i( id updated_at created_at )
@@ -8,6 +8,8 @@ module EitilCore
8
8
  module ApplicationRecord
9
9
  module WhereLike
10
10
 
11
+ Eitil::ApplicationRecordModules << self
12
+
11
13
  def where_like(_hash)
12
14
  column, like = _hash.first
13
15
  where("LOWER(#{column}) LIKE ?", "%#{like.downcase}%")
@@ -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
@@ -4,5 +4,6 @@ require "eitil_wrapper"
4
4
  require "eitil_wrapper/jobs"
5
5
  require "eitil_wrapper/scopes"
6
6
  require "eitil_wrapper/routes"
7
+ require "eitil_wrapper/callbacks"
7
8
  require "eitil_wrapper/decorators"
8
9
  require "eitil_wrapper/request_logger"
@@ -0,0 +1,2 @@
1
+
2
+ require "eitil_wrapper/callbacks/helper_methods"
@@ -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
@@ -5,6 +5,7 @@ module Eitil
5
5
 
6
6
  Root = Gem.loaded_specs['eitil'].full_gem_path
7
7
  Layers = %w( eitil_core eitil_support eitil_wrapper eitil_store eitil_integrate )
8
+ ApplicationRecordModules = []
8
9
 
9
10
  end
10
11
 
data/lib/eitil/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Eitil
2
2
 
3
- VERSION = '1.1.19'
3
+ VERSION = '1.1.20'
4
4
 
5
5
  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: 1.1.19
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-07-27 00:00:00.000000000 Z
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