eitil 2.0.2 → 2.0.3

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: '0802e48716390e5f61d59f0d2570ac69d5415acde68765fc9fddfe82e5c9763b'
4
- data.tar.gz: 9506323a1f016ff4471223699c9bbef4b37b7763860843161283f582a8eeb4a8
3
+ metadata.gz: f5c9cca8a4db961ae507f9326d97344ccb4de0c92b6c5104b1736b37e10c8498
4
+ data.tar.gz: 5ab03a4673c04380440686de8b702ab6e9f241240cdff749d1ddcf85a753c660
5
5
  SHA512:
6
- metadata.gz: 62cf3074ea2d8da505756ecd02e1d7d97b6eb4c3c716683b5c907b6187d8f2b919dd7d7ae7bf9e436e939fa4e5793d532809309c64c65b157d835e2604cf49f6
7
- data.tar.gz: 812edd949148e566c0930ffa47bd8104043f6538a061129a940c35c0b6c418333148ed2d7393761b744e22f8c666a44bbd1d42bef33e244253e66089ea04675c
6
+ metadata.gz: 62c4d31b23148b143ec87613f8b7e102db21d44709904449c85d938ebfd8b4fe7997814ecb96921ca73964d02aa1354d5214c9534faa6c7ef204c47259f35275
7
+ data.tar.gz: e7b017c534422ecd3b5f4e648def6197817094e7a40a313c4eaebe7794cffd183be51efe7670629044db372fe6a0e8d3c86c2587233b469df990a9b429c70146
data/README.md CHANGED
@@ -12,7 +12,6 @@ Our gem currently exists of five seperate layers (Railties), which can be integr
12
12
 
13
13
  - EitilCore, [docs](/eitil_core) > extends the core classes of Ruby and rails.
14
14
  - EitilSupport, [docs](/eitil_support) > provides utility through stand-alone classes and modules.
15
- - EitilWrapper, [docs](/eitil_wrapper) > wraps core rails operations with extended utilities – such as routing, jobs and decoraters.
16
15
  - EitilStore, [docs](/eitil_store) > stores data in containers, such as Regexp instances.
17
16
  - EitilIntegrate, [docs](/eitil_integrate) > provides seamless integrations with select gems and API's, through helper methods stored in PORO's.
18
17
 
data/lib/eitil/railtie.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  module Eitil
7
7
 
8
8
  Root = Gem.loaded_specs['eitil']&.full_gem_path
9
- Layers = %w( eitil_core eitil_support eitil_wrapper eitil_store eitil_integrate )
9
+ Layers = %w( eitil_core eitil_support eitil_store eitil_integrate )
10
10
  ApplicationRecordModules = []
11
11
 
12
12
  end
data/lib/eitil/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Eitil
2
2
 
3
- VERSION = '2.0.2'
3
+ VERSION = '2.0.3'
4
4
 
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -8,13 +8,11 @@ require 'eitil'
8
8
 
9
9
  require "eitil_core/railtie"
10
10
  require "eitil_integrate/railtie"
11
- require "eitil_wrapper/railtie"
12
11
  # require "eitil_store/railtie"
13
12
  # require "eitil_support/railtie"
14
13
 
15
14
  require "eitil_core"
16
15
  require "eitil_integrate"
17
- require "eitil_wrapper"
18
16
  # require "eitil_store"
19
17
  # require "eitil_support"
20
18
 
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: 2.0.2
4
+ version: 2.0.3
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-10-15 00:00:00.000000000 Z
11
+ date: 2021-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -271,24 +271,6 @@ files:
271
271
  - eitil_support/lib/eitil_support/stacktrace/audit.rb
272
272
  - eitil_support/lib/eitil_support/stacktrace/call.rb
273
273
  - eitil_support/lib/eitil_support/stacktrace/stack.rb
274
- - eitil_wrapper/README.md
275
- - eitil_wrapper/lib/eitil_wrapper.rb
276
- - eitil_wrapper/lib/eitil_wrapper/callbacks.rb
277
- - eitil_wrapper/lib/eitil_wrapper/callbacks/helper_methods.rb
278
- - eitil_wrapper/lib/eitil_wrapper/jobs.rb
279
- - eitil_wrapper/lib/eitil_wrapper/jobs/new_job.rb
280
- - eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
281
- - eitil_wrapper/lib/eitil_wrapper/jobs/single_method_job.rb
282
- - eitil_wrapper/lib/eitil_wrapper/railtie.rb
283
- - eitil_wrapper/lib/eitil_wrapper/records.rb
284
- - eitil_wrapper/lib/eitil_wrapper/records/default_calculators.rb
285
- - eitil_wrapper/lib/eitil_wrapper/records/default_scopes.rb
286
- - eitil_wrapper/lib/eitil_wrapper/records/default_sorts.rb
287
- - eitil_wrapper/lib/eitil_wrapper/request_logger.rb
288
- - eitil_wrapper/lib/eitil_wrapper/request_logger/controller_mixin.rb
289
- - eitil_wrapper/lib/eitil_wrapper/request_logger/logger_job.rb
290
- - eitil_wrapper/lib/eitil_wrapper/routes.rb
291
- - eitil_wrapper/lib/eitil_wrapper/routes/extended_resources.rb
292
274
  - lib/eitil.rb
293
275
  - lib/eitil/all.rb
294
276
  - lib/eitil/railtie.rb
@@ -1,271 +0,0 @@
1
-
2
-
3
-
4
- # EitilWrapper
5
-
6
- EitilWrapper wraps core rails operations with extended utilities – such as routing, jobs and decoraters.
7
-
8
-
9
-
10
-
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
-
40
- ## EitilWrapper::Jobs
41
-
42
- ```ruby
43
-
44
- require "eitil_wrapper/jobs"
45
-
46
- ```
47
-
48
- The Eitil jobs wrapper enables you to create perform_now and perform_later jobs on the fly, without the need to create a new class and file.
49
-
50
- The macro new_job accepts a :method as argument and defines a new method :method_job. The newly defined :method_job, when called, performs the orginal :method in the background. The new_job macro accepts both instance methods and singleton methods, which are defined within there own method scope.
51
-
52
- In contrast, the new_job_now macro defines a new :method_job_now method, which performs in the foreground.
53
-
54
- ```ruby
55
- # require "eitil_wrapper/jobs/new_job"
56
-
57
- new_job(_method, *args, **kwargs)
58
- # assuming a method :hello_world, call as: new_job :hello_world
59
- # => defines :hello_world_job
60
- ```
61
-
62
- ```ruby
63
- # require "eitil_wrapper/jobs/new_job_now"
64
-
65
- new_job_now(_method, *args, **kwargs)
66
- # assuming a method :hello_world, call as: new_job_now :hello_world
67
- # => defines :hello_world_job_now
68
- ```
69
-
70
-
71
-
72
-
73
-
74
- ## EitilWrapper::Routes
75
-
76
- ```ruby
77
-
78
- require "eitil_wrapper/routes"
79
-
80
- ```
81
-
82
- The Eitil router wrapper enables you to easily create new routes that can be shared among controllers. In that sense, it is as a custom extension of the built-in resourceful routes.
83
-
84
- ### New route
85
-
86
- The first macro, .new_route, enables you to create new route objects which may be called and used by different controllers.
87
-
88
- ```ruby
89
- # require "eitil_wrapper/routes/extended_resources"
90
-
91
- new_route(verb, _method, action, scope)
92
- # call as: new_route :post, :attachment, "add_attachment", :member
93
- ```
94
-
95
- - verb refers to the http_verb, e.g. :put.
96
- - method refers to the given http method (e.g. 'users/:id'). Additionally, this is the name you will refer to in order to include the route into a controller. Therefore the argument should be unique among all other routes.
97
- - action refers to the controller action to which you want to redirect to request, e.g. :update_user.
98
- - scope refers to the url and can be set to either :member or :collection.
99
-
100
- ### Add route
101
-
102
- The second macro, extended_resources, enables you to create all standard resources for a controller and add your own standardized routes. This macro works the same as the built-in :resources, except that you can pass more arguments to only: [], which adds the routes to your controller.
103
-
104
- ```ruby
105
- # require "eitil_wrapper/routes/extended_resources"
106
-
107
- extended_resources(controller, **kwargs)
108
- # call as: extended_resources :posts, only: [:create, :update, :attachment]
109
- ```
110
-
111
-
112
-
113
-
114
-
115
- ## EitilWrapper::Records
116
-
117
- ```ruby
118
-
119
- # include all below EitilWrapper::Records helpers through:
120
- require "eitil_wrapper/records"
121
-
122
- ```
123
-
124
- ### Scopes
125
-
126
- ```ruby
127
-
128
- require "eitil_wrapper/records/scopes"
129
-
130
- ```
131
-
132
- Scopes are generated through the columns of your model's database table. Which scopes are generated depends on the datatype of a column. For example, if your User model with table users has a column is_manager, a scope :is_manager_true is generated for your User model. A scope method is defined only if it does not already responds to another method of the same name. The scopes generated are:
133
-
134
- ```ruby
135
- # require "eitil_wrapper/scopes/default_scopes"
136
-
137
- # columns of datatype: boolean
138
- .{column_name}_true
139
- .{column_name}_false
140
-
141
- # columns of datatype: datetime
142
- .{column_name}_today
143
- .{column_name}_past
144
- .{column_name}_future
145
- .{column_name}_on_date(date)
146
- .{column_name}_before_date(date)
147
- .{column_name}_after_date(date)
148
- .{column_name}_between_dates(start_date, end_date)
149
-
150
- # columns of datatype: date
151
- .{column_name}_today
152
- .{column_name}_past
153
- .{column_name}_future
154
- .{column_name}_on_date(date)
155
- .{column_name}_before_date(date)
156
- .{column_name}_after_date(date)
157
- .{column_name}_between_dates(start_date, end_date)
158
-
159
- # columns of datatype: integer
160
- .{column_name}_equal_to(number)
161
- .{column_name}_lower_than(number)
162
- .{column_name}_higher_than(number)
163
- .{column_name}_between(min, max)
164
-
165
- # columns of datatype: float
166
- .{column_name}_equal_to(number)
167
- .{column_name}_lower_than(number)
168
- .{column_name}_higher_than(number)
169
- .{column_name}_between(min, max)
170
- ```
171
-
172
- ### Sorts
173
-
174
-
175
- ```ruby
176
-
177
- require "eitil_wrapper/records/sorts"
178
-
179
- ```
180
-
181
- Sorts are generated through the columns of your model's database table. Which sorts are generated depends on the datatype of a column. A sort method is defined only if it does not already responds to another method of the same name. The sorts generated are:
182
-
183
- ```ruby
184
- # require "eitil_wrapper/scopes/default_scopes"
185
-
186
- # columns of datatype: datetime
187
- .{column_name}_oldest_first
188
- .{column_name}_newest_first
189
-
190
- # columns of datatype: date
191
- .{column_name}_oldest_first
192
- .{column_name}_newest_first
193
-
194
- # columns of datatype: integer
195
- .{column_name}_ascending
196
- .{column_name}_descending
197
-
198
- # columns of datatype: float
199
- .{column_name}_ascending
200
- .{column_name}_descending
201
- ```
202
-
203
-
204
- ### Calculators
205
-
206
-
207
- ```ruby
208
-
209
- require "eitil_wrapper/records/calculators"
210
-
211
- ```
212
-
213
- Calculators are generated through the columns of your model's database table. Which calculators are generated depends on the datatype of a column. A calculator method is defined only if it does not already responds to another method of the same name. The calculators generated are:
214
-
215
- ```ruby
216
- # require "eitil_wrapper/scopes/default_scopes"
217
-
218
- # columns of datatype: array (serialized)
219
- .{column_name}_sum # returns all uniq elements in a new, single array
220
- .{column_name}_sum_i # sum and map to integer
221
- .{column_name}_sum_f # sum and map to float
222
- .{column_name}_sum_d # sum and map to decimal
223
-
224
- # columns of datatype: integer
225
- .{column_name}_max
226
- .{column_name}_min
227
- .{column_name}_sum
228
- .{column_name}_avg
229
-
230
- # columns of datatype: float
231
- .{column_name}_max
232
- .{column_name}_min
233
- .{column_name}_sum
234
- .{column_name}_avg
235
-
236
- # columns of datatype: decimal
237
- .{column_name}_max
238
- .{column_name}_min
239
- .{column_name}_sum
240
- .{column_name}_avg
241
-
242
- # columns of datatype: bigint
243
- .{column_name}_max
244
- .{column_name}_min
245
- .{column_name}_sum
246
- .{column_name}_avg
247
- ```
248
-
249
-
250
-
251
- ## EitilWrapper::RequestLogger
252
-
253
- ```ruby
254
-
255
- require "eitil_wrapper/request_logger"
256
-
257
- ```
258
-
259
- The RequestLogger wrapper logs request params in /log/request_logger.log, which offers the opportunity to pry into webhooks while developing. In order to track a controller, simply add the following. This calls a background job which writes to the file.
260
-
261
- ```ruby
262
-
263
- include EitilWrapper::RequestLogger::ControllerMixin
264
- before_action :log_request
265
-
266
- ```
267
-
268
-
269
-
270
-
271
-
@@ -1,118 +0,0 @@
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
- return if Eitil.skip_callback_helper_methods_for_models.include?(subclass.to_s.to_sym)
18
-
19
- # Set the proper table_names for namespaced models. Without setting this,
20
- # Rails run into problems due to the fact that the first call to the model's
21
- # constant triggers this initializer first, and only thereafter the model file
22
- # which sets the correct table_name through a macro.
23
- namespaced_class = subclass.to_s.include?('::')
24
- subclass.table_name = subclass.to_s.gsub('::', '_').downcase.pluralize if namespaced_class
25
-
26
- subclass.use_eitil_callback_helper_methods
27
-
28
- rescue => e
29
- puts "callback helper methods failed for #{subclass} because of #{e.class} and '#{e.to_s.split(' ').first}'"
30
- end
31
-
32
- def use_eitil_callback_helper_methods
33
- return if abstract_class?
34
- create_eitil_boolean_callback_helper_methods
35
- end
36
-
37
- def columns_of_type(data_type)
38
- columns_hash.select { |column,v| v.sql_type_metadata.type == data_type }
39
- end
40
-
41
- def create_eitil_boolean_callback_helper_methods
42
- columns = columns_of_type :boolean
43
- columns&.each do |column_name, eitil_object|
44
-
45
- # truthy methods
46
- create_eitil_became_true_callback_helper column_name
47
- create_eitil_becomes_true_callback_helper column_name
48
- create_eitil_to_true_callback_helper column_name
49
-
50
- # falsy methods
51
- create_eitil_became_false_callback_helper column_name
52
- create_eitil_becomes_false_callback_helper column_name
53
- create_eitil_to_false_callback_helper column_name
54
-
55
- end
56
- end
57
-
58
- def create_eitil_became_true_callback_helper(column_name)
59
- method_name = "#{column_name}_became_true"
60
-
61
- define_method(method_name) do
62
- _changes = previous_changes[column_name]
63
- _changes && !_changes[0] && _changes[1]
64
- end
65
- end
66
-
67
- def create_eitil_becomes_true_callback_helper(column_name)
68
- method_name = "#{column_name}_becomes_true"
69
-
70
- define_method(method_name) do
71
- _changes = changes[column_name]
72
- _changes && !_changes[0] && _changes[1]
73
- end
74
- end
75
-
76
- def create_eitil_to_true_callback_helper(column_name)
77
- method_name = "#{column_name}_to_true"
78
- becomes_method = "#{column_name}_becomes_true"
79
- became_method = "#{column_name}_became_true"
80
-
81
- define_method(method_name) do
82
- return send(becomes_method) if changes&.present?
83
- return send(became_method) if previous_changes&.present?
84
- end
85
- end
86
-
87
- def create_eitil_became_false_callback_helper(column_name)
88
- method_name = "#{column_name}_became_false"
89
-
90
- define_method(method_name) do
91
- _changes = previous_changes[column_name]
92
- _changes && _changes[0] && !_changes[1]
93
- end
94
- end
95
-
96
- def create_eitil_becomes_false_callback_helper(column_name)
97
- method_name = "#{column_name}_becomes_false"
98
-
99
- define_method(method_name) do
100
- _changes = changes[column_name]
101
- _changes && _changes[0] && !_changes[1]
102
- end
103
- end
104
-
105
- def create_eitil_to_false_callback_helper(column_name)
106
- method_name = "#{column_name}_to_false"
107
- becomes_method = "#{column_name}_becomes_false"
108
- became_method = "#{column_name}_became_false"
109
-
110
- define_method(method_name) do
111
- return send(becomes_method) if changes&.present?
112
- return send(became_method) if previous_changes&.present?
113
- end
114
- end
115
-
116
- end
117
- end
118
- end
@@ -1,2 +0,0 @@
1
-
2
- require "eitil_wrapper/callbacks/helper_methods"
@@ -1,34 +0,0 @@
1
-
2
- # require "eitil_wrapper/jobs/new_job"
3
-
4
- require "eitil_wrapper/jobs/single_method_job"
5
-
6
- Kernel.module_eval do
7
-
8
- # BEWARE: _self is currently not accepted in perform_later jobs due to serialization errors
9
-
10
- # The cases of 'id' and '_self' both handle instances, with the difference
11
- # being that 'id' works for objects that have a database record, while '_self'
12
- # works for non database supported instanes, such as an Exporter instance.
13
-
14
- def new_job(_method, *args, **kwargs)
15
-
16
- if instance_methods(false).include? _method
17
- define_method "#{_method}_job" do |_self = nil, *args, **kwargs|
18
-
19
- EitilWrapper::SingleMethodJob.perform_later(
20
- *args, _class: self.class.to_s, _method: _method.to_s, id: safe_send(:id), _self: self.to_json, **kwargs
21
- )
22
- end
23
-
24
- elsif singleton_methods(false).include? _method
25
- define_singleton_method "#{_method}_job" do |*args, **kwargs|
26
-
27
- EitilWrapper::SingleMethodJob.perform_later(
28
- *args, _class: to_s, _method: _method.to_s, **kwargs
29
- )
30
- end
31
- end
32
- end
33
-
34
- end
@@ -1,37 +0,0 @@
1
-
2
- # require "eitil_wrapper/jobs/new_job_now"
3
-
4
- require "eitil_wrapper/jobs/single_method_job"
5
-
6
- # BEWARE: This is an exact copy of the .new_job method, except for .perform_now instead of .perform_later and the method's name.
7
- # The reason for not using helper methods is to not unnecessarily fill and potentially fuck up the Kernel environment.
8
-
9
- Kernel.module_eval do
10
-
11
- # BEWARE: _self is currently not accepted in perform_later jobs due to serialization errors
12
-
13
- # The cases of 'id' and '_self' both handle instances, with the difference
14
- # being that 'id' works for objects that have a database record, while '_self'
15
- # works for non database supported instanes, such as an Exporter instance.
16
-
17
- def new_job_now(_method, *args, **kwargs)
18
-
19
- if instance_methods(false).include? _method
20
- define_method "#{_method}_job_now" do |_self = nil, *args, **kwargs|
21
-
22
- EitilWrapper::SingleMethodJob.perform_now(
23
- *args, _class: self.class.to_s, _method: _method.to_s, id: safe_send(:id), _self: self.to_json, **kwargs
24
- )
25
- end
26
-
27
- elsif singleton_methods(false).include? _method
28
- define_singleton_method "#{_method}_job_now" do |*args, **kwargs|
29
-
30
- EitilWrapper::SingleMethodJob.perform_now(
31
- *args, _class: to_s, _method: _method.to_s, **kwargs
32
- )
33
- end
34
- end
35
- end
36
-
37
- end
@@ -1,11 +0,0 @@
1
- # ISSUE: this code is currently defined eitil_wrapper/railtie.rb, since module inclusion
2
- # somehow leads to errors in the initialization process. Ideally, this code would be
3
- # defined in eitil_wrapper/jobs/single_method_job.rb and dispatched in eitil_wrapper/railtie.rb
4
-
5
- # require "eitil_wrapper/railtie" to run the dynamic dispatch as an init hook during boot
6
- require "eitil_wrapper/railtie"
7
-
8
- module EitilWrapper
9
- module CreateSingleMethodJob
10
- end
11
- end
@@ -1,4 +0,0 @@
1
-
2
- require "eitil_wrapper/jobs/new_job"
3
- require "eitil_wrapper/jobs/new_job_now"
4
- require "eitil_wrapper/jobs/single_method_job"
@@ -1,94 +0,0 @@
1
-
2
- module EitilWrapper
3
-
4
- class Railtie < Rails::Railtie
5
-
6
- # Dynamic dispatching after initialization of Rails classes.
7
-
8
- initializer "my_railtie.configure_rails_initialization", options: :after do |app|
9
-
10
- if Object.const_defined?('EitilWrapper::Records::DefaultCalculators')
11
- ::ApplicationRecord.send(:extend, EitilWrapper::Records::DefaultCalculators)
12
- end
13
-
14
- if Object.const_defined?('EitilWrapper::Records::DefaultScopes')
15
- ::ApplicationRecord.send(:extend, EitilWrapper::Records::DefaultScopes)
16
- end
17
-
18
- if Object.const_defined?('EitilWrapper::Records::DefaultSorts')
19
- ::ApplicationRecord.send(:extend, EitilWrapper::Records::DefaultSorts)
20
- end
21
-
22
- if Object.const_defined?('EitilWrapper::Callbacks::HelperMethods')
23
- ::ApplicationRecord.send(:extend, EitilWrapper::Callbacks::HelperMethods)
24
- end
25
-
26
- if Object.const_defined?('EitilWrapper::CreateSingleMethodJob')
27
-
28
- # ISSUE: this code is currently defined eitil_wrapper/railtie.rb, since module inclusion
29
- # somehow leads to errors in the initialization process. Ideally, this code would be
30
- # defined in eitil_wrapper/jobs/single_method_job.rb and dispatched in eitil_wrapper/railtie.rb
31
-
32
- # BEWARE: _self is currently not accepted in perform_later jobs due to serialization errors
33
-
34
- # BEWARE: The cases of 'id' and '_self' both handle instances, with the difference
35
- # being that 'id' works for objects that have a database record, while '_self'
36
- # works for non database supported instanes, such as an Exporter instance.
37
-
38
- module ::EitilWrapper
39
-
40
- class ::ApplicationJob < ActiveJob::Base
41
- end
42
-
43
- class SingleMethodJob < ::ApplicationJob
44
- def perform(*args, _class:, _method:, id: nil, _self: nil, **kwargs)
45
- object =
46
- if id
47
- _class.constantize.find(id)
48
- elsif _self
49
- _self
50
- else
51
- _class.constantize
52
- end
53
-
54
- if args.present? and kwargs.present?
55
- object.send _method, *args, **kwargs
56
-
57
- elsif args.present?
58
- object.send _method, *args
59
-
60
- elsif kwargs.present?
61
- object.send _method, **kwargs
62
-
63
- else
64
- object.send _method
65
- end
66
-
67
- end; end; end; end
68
-
69
-
70
- if Object.const_defined?('EitilWrapper::RequestLogger::CreateLoggerJob')
71
-
72
- module ::EitilWrapper
73
- module RequestLogger
74
- class LoggerJob < ::ApplicationJob
75
-
76
- def perform(logger_object)
77
-
78
- # set path for logger
79
- $request_logger_path ||= "#{Rails.root}/log/request_logger.log"
80
-
81
- # create logger, if not present
82
- if Dir[$request_logger_path].blank? || $request_logger.blank?
83
- $request_logger = Logger.new($request_logger_path)
84
- end
85
-
86
- # add logger_object to logger
87
- $request_logger.info(logger_object)
88
-
89
- end; end; end; end; end
90
-
91
- end
92
-
93
- end
94
- end
@@ -1,104 +0,0 @@
1
-
2
- # require "eitil_wrapper/records/default_calculators"
3
-
4
- # require "eitil_wrapper/railtie" to run the dynamic dispatch as an init hook during boot
5
- require "eitil_wrapper/railtie"
6
-
7
- module EitilWrapper
8
- module Records
9
- module DefaultCalculators
10
-
11
- Eitil::ApplicationRecordModules << self
12
-
13
- SharableNumberCalculators = -> (_class, column) {
14
- _class.eitil_calculator :"#{column}_max", -> { _class.maximum(column) }
15
- _class.eitil_calculator :"#{column}_min", -> { _class.minimum(column) }
16
- _class.eitil_calculator :"#{column}_sum", -> { _class.sum(column) }
17
- _class.eitil_calculator :"#{column}_avg", -> { _class.average(column) }
18
- }
19
-
20
- SharableIterableCalculators = -> (_class, column) {
21
- _class.eitil_calculator :"#{column}_sum", -> { _class.pluck(column).flatten!.uniq }
22
- _class.eitil_calculator :"#{column}_sum_i", -> { _class.pluck(column).flatten!.uniq.map(&:to_i) }
23
- _class.eitil_calculator :"#{column}_sum_f", -> { _class.pluck(column).flatten!.uniq.map(&:to_f) }
24
- _class.eitil_calculator :"#{column}_sum_d", -> { _class.pluck(column).flatten!.uniq.map(&:to_d) }
25
- }
26
-
27
- def inherited(subclass)
28
- super
29
- return if Eitil.skip_default_calculators_for_models.include?(subclass.to_s.to_sym)
30
-
31
- # Set the proper table_names for namespaced models. Without setting this,
32
- # Rails run into problems due to the fact that the first call to the model's
33
- # constant triggers this initializer first, and only thereafter the model file
34
- # which sets the correct table_name through a macro.
35
-
36
- namespaced_class = subclass.to_s.include?('::')
37
- subclass.table_name = subclass.to_s.gsub('::', '_').downcase.pluralize if namespaced_class
38
-
39
- subclass.use_eitil_calculators
40
-
41
- rescue => e
42
- puts "default calculators failed for class '#{subclass}' with expected table '#{subclass.table_name}' because of #{e.class} and '#{e.to_s.split(' ').first}'"
43
- end
44
-
45
- def use_eitil_calculators
46
- return if abstract_class?
47
-
48
- # text[] is postgresql's datatype for serialized arrays
49
- # numeric is postgresql's datatype for decimals
50
- # double precision is postgresql's datatype for floats
51
-
52
-
53
- %w[integer bigint double\ precision numeric].each do |_type|
54
- send :"create_eitil_#{_type.gsub(' ','_')}_calculators"
55
- end
56
-
57
- create_array_calculators
58
- end
59
-
60
- def eitil_calculator(_name, _proc)
61
- # skip calculator methods for primary and foreign key columns
62
- return if _name.to_s =~ /^id_[a-z]{1,}$/ || _name.to_s =~ /_id_[a-z]{1,}$/
63
-
64
- define_singleton_method(_name) { _proc.call } unless respond_to? _name
65
- end
66
-
67
- def calculator_columns_of_type(data_type)
68
- columns_hash.select { |column,v| v.sql_type == data_type }
69
- end
70
-
71
- def create_eitil_integer_calculators
72
- calculator_columns_of_type("integer")&.map do |column, object|
73
- SharableNumberCalculators.call self, column
74
- end
75
- end
76
-
77
- def create_eitil_bigint_calculators
78
- calculator_columns_of_type("bigint")&.map do |column, object|
79
- SharableNumberCalculators.call self, column
80
- end
81
- end
82
-
83
- def create_eitil_double_precision_calculators
84
- calculator_columns_of_type("double\ precision")&.map do |column, object|
85
- SharableNumberCalculators.call self, column
86
- end
87
- end
88
-
89
- def create_eitil_numeric_calculators
90
- calculator_columns_of_type("numeric")&.map do |column, object|
91
- SharableNumberCalculators.call self, column
92
- end
93
- end
94
-
95
- def create_array_calculators
96
- columns = columns_hash.select { |column,v| v.sql_type == "text" && v.default == "{}" }
97
- columns&.map do |column, object|
98
- SharableIterableCalculators.call self, column
99
- end
100
- end
101
-
102
- end
103
- end
104
- end
@@ -1,95 +0,0 @@
1
-
2
- # require "eitil_wrapper/records/default_scopes"
3
-
4
- # require "eitil_wrapper/railtie" to run the dynamic dispatch as an init hook during boot
5
- require "eitil_wrapper/railtie"
6
-
7
- module EitilWrapper
8
- module Records
9
- module DefaultScopes
10
-
11
- Eitil::ApplicationRecordModules << self
12
-
13
- SharableDateScopes = -> (_class, column) {
14
- _class.eitil_scope :"#{column}_today", -> { where("#{column} = ?", Date.today) }
15
- _class.eitil_scope :"#{column}_past", -> { where("#{column} < ?", Date.today) }
16
- _class.eitil_scope :"#{column}_future", -> { where("#{column} > ?", Date.today) }
17
-
18
- _class.eitil_scope :"#{column}_on_date", -> (date) { where("#{column} = ?", date) }
19
- _class.eitil_scope :"#{column}_before_date", -> (date) { where("#{column} = ?", date) }
20
- _class.eitil_scope :"#{column}_after_date", -> (date) { where("#{column} = ?", date) }
21
- _class.eitil_scope :"#{column}_between_dates", -> (from, till) { where("#{column} >= ? and #{column} <= ?", from, till) }
22
- }
23
-
24
- SharableNumScopes = -> (_class, column) {
25
- _class.eitil_scope :"#{column}_equal_to", -> (number) { where("#{column} = ?", number) }
26
- _class.eitil_scope :"#{column}_lower_than", -> (number) { where("#{column} = <", number) }
27
- _class.eitil_scope :"#{column}_higher_than", -> (number) { where("#{column} = >", number) }
28
- _class.eitil_scope :"#{column}_between", -> (min, max) { where("#{column} >= ? and #{column} <= ?", min, max) }
29
- }
30
-
31
- def inherited(subclass)
32
- super
33
- return if Eitil.skip_default_scopes_for_models.include?(subclass.to_s.to_sym)
34
-
35
- # Set the proper table_names for namespaced models. Without setting this,
36
- # Rails run into problems due to the fact that the first call to the model's
37
- # constant triggers this initializer first, and only thereafter the model file
38
- # which sets the correct table_name through a macro.
39
-
40
- namespaced_class = subclass.to_s.include?('::')
41
- subclass.table_name = subclass.to_s.gsub('::', '_').downcase.pluralize if namespaced_class
42
-
43
- subclass.use_eitil_scopes
44
-
45
- rescue => e
46
- puts "default scopes failed for class '#{subclass}' with expected table '#{subclass.table_name}' because of #{e.class} and '#{e.to_s.split(' ').first}'"
47
- end
48
-
49
- def use_eitil_scopes
50
- return if abstract_class?
51
- %i[boolean datetime date integer float].each { |_type| send :"create_eitil_#{_type}_scopes" }
52
- end
53
-
54
- def eitil_scope(_name, _proc)
55
- scope _name, _proc unless respond_to? _name
56
- end
57
-
58
- def columns_of_type(data_type)
59
- columns_hash.select { |column,v| v.sql_type_metadata.type == data_type }
60
- end
61
-
62
- def create_eitil_boolean_scopes
63
- columns_of_type(:boolean)&.map do |column, object|
64
- eitil_scope :"#{column}_true", -> { where(column => true) }
65
- eitil_scope :"#{column}_false", -> { where(column => [false, nil]) }
66
- end
67
- end
68
-
69
- def create_eitil_datetime_scopes
70
- columns_of_type(:datetime)&.map do |column, object|
71
- SharableDateScopes.call self, column
72
- end
73
- end
74
-
75
- def create_eitil_date_scopes
76
- columns_of_type(:date)&.map do |column, object|
77
- SharableDateScopes.call self, column
78
- end
79
- end
80
-
81
- def create_eitil_integer_scopes
82
- columns_of_type(:integer)&.map do |column, object|
83
- SharableNumScopes.call self, column
84
- end
85
- end
86
-
87
- def create_eitil_float_scopes
88
- columns_of_type(:float)&.map do |column, object|
89
- SharableNumScopes.call self, column
90
- end
91
- end
92
-
93
- end
94
- end
95
- end
@@ -1,81 +0,0 @@
1
-
2
- # require "eitil_wrapper/records/default_sorts"
3
-
4
- # require "eitil_wrapper/railtie" to run the dynamic dispatch as an init hook during boot
5
- require "eitil_wrapper/railtie"
6
-
7
-
8
- module EitilWrapper
9
- module Records
10
- module DefaultSorts
11
-
12
- Eitil::ApplicationRecordModules << self
13
-
14
- SharableDateSorts = -> (_class, column) {
15
- _class.eitil_sort :"#{column}_oldest_first", -> { _class.order("#{column} ASC") }
16
- _class.eitil_sort :"#{column}_newest_first", -> { _class.order("#{column} DESC") }
17
- }
18
-
19
- SharableNumSorts = -> (_class, column) {
20
- _class.eitil_sort :"#{column}_ascending", -> { _class.order("#{column} ASC") }
21
- _class.eitil_sort :"#{column}_descending", -> { _class.order("#{column} DESC") }
22
- }
23
-
24
- def inherited(subclass)
25
- super
26
- return if Eitil.skip_default_sorts_for_models.include?(subclass.to_s.to_sym)
27
-
28
- # Set the proper table_names for namespaced models. Without setting this,
29
- # Rails run into problems due to the fact that the first call to the model's
30
- # constant triggers this initializer first, and only thereafter the model file
31
- # which sets the correct table_name through a macro.
32
-
33
- namespaced_class = subclass.to_s.include?('::')
34
- subclass.table_name = subclass.to_s.gsub('::', '_').downcase.pluralize if namespaced_class
35
-
36
- subclass.use_eitil_sorts
37
-
38
- rescue => e
39
- puts "default sorts failed for class '#{subclass}' with expected table '#{subclass.table_name}' because of #{e.class} and '#{e.to_s.split(' ').first}'"
40
- end
41
-
42
- def use_eitil_sorts
43
- return if abstract_class?
44
- %i[datetime date integer float].each { |_type| send :"create_eitil_#{_type}_sorts" }
45
- end
46
-
47
- def eitil_sort(_name, _proc)
48
- define_singleton_method(_name) { _proc.call } unless respond_to? _name
49
- end
50
-
51
- def sort_columns_of_type(data_type)
52
- columns_hash.select { |column,v| v.sql_type_metadata.type == data_type }
53
- end
54
-
55
- def create_eitil_datetime_sorts
56
- columns_of_type(:datetime)&.map do |column, object|
57
- SharableDateSorts.call self, column
58
- end
59
- end
60
-
61
- def create_eitil_date_sorts
62
- columns_of_type(:date)&.map do |column, object|
63
- SharableDateSorts.call self, column
64
- end
65
- end
66
-
67
- def create_eitil_integer_sorts
68
- columns_of_type(:integer)&.map do |column, object|
69
- SharableNumSorts.call self, column
70
- end
71
- end
72
-
73
- def create_eitil_float_sorts
74
- columns_of_type(:float)&.map do |column, object|
75
- SharableNumSorts.call self, column
76
- end
77
- end
78
-
79
- end
80
- end
81
- end
@@ -1,4 +0,0 @@
1
-
2
- require "eitil_wrapper/records/default_scopes"
3
- require "eitil_wrapper/records/default_calculators"
4
- require "eitil_wrapper/records/default_sorts"
@@ -1,48 +0,0 @@
1
-
2
- # require "eitil_wrapper/request_logger/controller_mixin"
3
-
4
- require_relative "logger_job"
5
-
6
- module EitilWrapper
7
- module RequestLogger
8
- module ControllerMixin
9
-
10
- private
11
-
12
- def log_request
13
- $request_logger_path ||= "#{Rails.root}/log/request_logger.log"
14
- EitilWrapper::RequestLogger::LoggerJob.perform_later(request_logger_object)
15
- end
16
-
17
- def request_logger_object
18
-
19
- log_request = {
20
- path: request.env["REQUEST_PATH"],
21
- method: request.env["REQUEST_METHOD"],
22
- query_str: request.env["QUERY_STRING"],
23
- }
24
-
25
- log_params = {
26
- params: params.as_json
27
- }
28
-
29
- log_attributes = {
30
- time: Time.now.strftime("%Y-%m-%d %H:%M:%S")
31
- }
32
-
33
- log = {
34
- request: log_request,
35
- params: log_params,
36
- attributes: log_attributes
37
- }
38
-
39
- log_time = log_attributes[:time]
40
- log_strf = log.deep_symbolize_keys.to_s
41
- # log_strf may be hashed through eval(log_strf)
42
-
43
- return log_strf
44
- end
45
-
46
- end
47
- end
48
- end
@@ -1,17 +0,0 @@
1
-
2
- # require "eitil_wrapper/request_logger/logger_job"
3
-
4
- # require "eitil_wrapper/railtie" to run the dynamic dispatch as an init hook during boot
5
- require "eitil_wrapper/railtie"
6
-
7
- # ISSUE: this code is currently defined eitil_wrapper/railtie.rb, since module inclusion
8
- # somehow leads to errors in the initialization process. Ideally, this code would be
9
- # defined in eitil_wrapper/request_logger/logger_job.rb and dispatched in eitil_wrapper/railtie.rb
10
-
11
- module EitilWrapper
12
- module RequestLogger
13
- module CreateLoggerJob
14
-
15
- end
16
- end
17
- end
@@ -1,5 +0,0 @@
1
-
2
- # require "eitil_wrapper/request_logger"
3
-
4
- require_relative "request_logger/controller_mixin"
5
- require_relative "request_logger/logger_job"
@@ -1,40 +0,0 @@
1
- module EitilWrapper
2
- module ExtendedResources
3
-
4
- RESOURCEFUL_ACTIONS = %i$ index new create show edit update destroy $
5
-
6
- private
7
-
8
- def extended_resources(controller, **kwargs)
9
- all_args_to_ivars binding
10
-
11
- resources(controller, **resource_args) do
12
- extended_routes&.each { |route| send(route).call controller }
13
- yield if block_given?
14
- end
15
- end
16
-
17
- def resource_args
18
- duplicate = @kwargs.dup
19
- duplicate[:only] = resourceful_routes
20
- duplicate
21
- end
22
-
23
- def resourceful_routes
24
- @kwargs.dig(:only) - extended_routes
25
- end
26
-
27
- def extended_routes
28
- @kwargs.dig(:only) - RESOURCEFUL_ACTIONS
29
- end
30
-
31
- def new_route(verb, _method, action, scope)
32
- self.class.send :define_method, _method do
33
- -> (controller) { send(verb, _method, to: "#{controller}##{action}", on: scope) }
34
- end
35
- end
36
-
37
- end
38
- end
39
-
40
- ActionDispatch::Routing::Mapper.__send__ :include, EitilWrapper::ExtendedResources
@@ -1,2 +0,0 @@
1
-
2
- require "eitil_wrapper/routes/extended_resources"
@@ -1,8 +0,0 @@
1
-
2
- require "eitil_wrapper"
3
-
4
- require "eitil_wrapper/jobs"
5
- require "eitil_wrapper/records"
6
- require "eitil_wrapper/routes"
7
- require "eitil_wrapper/callbacks"
8
- require "eitil_wrapper/request_logger"