eitil 1.4.1 → 2.0.3
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/README.md +0 -1
- data/eitil_integrate/lib/eitil_integrate/application_exporter/lookups.rb +1 -1
- data/lib/eitil/railtie.rb +2 -3
- data/lib/eitil/version.rb +1 -1
- data/spec/dummy_app/app/controllers/application_controller.rb +0 -2
- data/spec/dummy_app/app/controllers/users_controller.rb +0 -31
- data/spec/dummy_app/config/routes.rb +0 -5
- data/spec/dummy_app/db/test.sqlite3 +0 -0
- data/spec/spec_helper.rb +0 -2
- metadata +2 -27
- data/eitil_wrapper/README.md +0 -309
- data/eitil_wrapper/lib/eitil_wrapper/callbacks/helper_methods.rb +0 -118
- data/eitil_wrapper/lib/eitil_wrapper/callbacks.rb +0 -2
- data/eitil_wrapper/lib/eitil_wrapper/decorators/application_decorator.rb +0 -22
- data/eitil_wrapper/lib/eitil_wrapper/decorators/controller_decorator.rb +0 -72
- data/eitil_wrapper/lib/eitil_wrapper/decorators.rb +0 -3
- data/eitil_wrapper/lib/eitil_wrapper/jobs/new_job.rb +0 -34
- data/eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb +0 -37
- data/eitil_wrapper/lib/eitil_wrapper/jobs/single_method_job.rb +0 -11
- data/eitil_wrapper/lib/eitil_wrapper/jobs.rb +0 -4
- data/eitil_wrapper/lib/eitil_wrapper/railtie.rb +0 -94
- data/eitil_wrapper/lib/eitil_wrapper/records/default_calculators.rb +0 -104
- data/eitil_wrapper/lib/eitil_wrapper/records/default_scopes.rb +0 -95
- data/eitil_wrapper/lib/eitil_wrapper/records/default_sorts.rb +0 -81
- data/eitil_wrapper/lib/eitil_wrapper/records.rb +0 -4
- data/eitil_wrapper/lib/eitil_wrapper/request_logger/controller_mixin.rb +0 -48
- data/eitil_wrapper/lib/eitil_wrapper/request_logger/logger_job.rb +0 -17
- data/eitil_wrapper/lib/eitil_wrapper/request_logger.rb +0 -5
- data/eitil_wrapper/lib/eitil_wrapper/routes/extended_resources.rb +0 -40
- data/eitil_wrapper/lib/eitil_wrapper/routes.rb +0 -2
- data/eitil_wrapper/lib/eitil_wrapper.rb +0 -9
- data/spec/dummy_app/app/decorators/address_decorator.rb +0 -3
- data/spec/dummy_app/app/decorators/application_decorator.rb +0 -12
- data/spec/dummy_app/app/decorators/user_decorator.rb +0 -19
- data/spec/eitil_wrapper/decorators/decorators_spec.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5c9cca8a4db961ae507f9326d97344ccb4de0c92b6c5104b1736b37e10c8498
|
4
|
+
data.tar.gz: 5ab03a4673c04380440686de8b702ab6e9f241240cdff749d1ddcf85a753c660
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
@@ -10,7 +10,7 @@ module EitilIntegrate::RubyXL
|
|
10
10
|
class << self
|
11
11
|
|
12
12
|
def exporter_paths
|
13
|
-
EitilSupport::Directory.files('app/exporters/exporters').select { |path| path.end_with? '_exporter.rb' }
|
13
|
+
EitilSupport::Directory.files('app/views/exporters/exporters').select { |path| path.end_with? '_exporter.rb' }
|
14
14
|
end
|
15
15
|
|
16
16
|
def exporter_names
|
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
|
9
|
+
Layers = %w( eitil_core eitil_support eitil_store eitil_integrate )
|
10
10
|
ApplicationRecordModules = []
|
11
11
|
|
12
12
|
end
|
@@ -45,10 +45,9 @@ module Eitil
|
|
45
45
|
yield Eitil
|
46
46
|
end
|
47
47
|
|
48
|
-
config_path = Rails.root + 'config/initializers/eitil.rb'
|
48
|
+
config_path = Rails.root + 'config/initializers/internal_engines/eitil.rb'
|
49
49
|
|
50
50
|
if File.exists? config_path
|
51
|
-
puts "Loading Eitil config from #{config_path}..."
|
52
51
|
load config_path
|
53
52
|
else
|
54
53
|
puts "Eitil config not found at #{config_path}, resorting to defaults..."
|
data/lib/eitil/version.rb
CHANGED
@@ -3,37 +3,6 @@ class UsersController < ApplicationController
|
|
3
3
|
before_action :set_user, only: [:show, :edit, :update, :destroy]
|
4
4
|
|
5
5
|
|
6
|
-
# ---
|
7
|
-
# Tests for EitilWrapper::Decorator
|
8
|
-
|
9
|
-
before_action :set_user, only: [:decorator_a, :decorator_b, :decorator_c, :decorator_d]
|
10
|
-
|
11
|
-
# default
|
12
|
-
def decorator_a
|
13
|
-
hash = decorate(@user)
|
14
|
-
render json: hash
|
15
|
-
end
|
16
|
-
|
17
|
-
# specific dec_method
|
18
|
-
def decorator_b
|
19
|
-
hash = decorate(@user, dec_method: :first_and_last_name)
|
20
|
-
render json: hash
|
21
|
-
end
|
22
|
-
|
23
|
-
# post request, with 'isWeb' and 'isMobile' params
|
24
|
-
def decorator_c
|
25
|
-
hash = decorate(@user)
|
26
|
-
render json: hash
|
27
|
-
end
|
28
|
-
|
29
|
-
# specific dec_class
|
30
|
-
def decorator_d
|
31
|
-
hash = decorate(@user, dec_class: :Application, dec_method: :timestamps)
|
32
|
-
render json: hash
|
33
|
-
end
|
34
|
-
|
35
|
-
# ---
|
36
|
-
|
37
6
|
|
38
7
|
|
39
8
|
# GET /users
|
@@ -4,9 +4,4 @@ Rails.application.routes.draw do
|
|
4
4
|
resources :addresses
|
5
5
|
resources :users
|
6
6
|
|
7
|
-
get 'users/:id/decorator_a' => 'users#decorator_a'
|
8
|
-
get 'users/:id/decorator_b' => 'users#decorator_b'
|
9
|
-
post 'users/:id/decorator_c' => 'users#decorator_c'
|
10
|
-
get 'users/:id/decorator_d' => 'users#decorator_d'
|
11
|
-
|
12
7
|
end
|
Binary file
|
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:
|
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-
|
11
|
+
date: 2021-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -271,27 +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/decorators.rb
|
279
|
-
- eitil_wrapper/lib/eitil_wrapper/decorators/application_decorator.rb
|
280
|
-
- eitil_wrapper/lib/eitil_wrapper/decorators/controller_decorator.rb
|
281
|
-
- eitil_wrapper/lib/eitil_wrapper/jobs.rb
|
282
|
-
- eitil_wrapper/lib/eitil_wrapper/jobs/new_job.rb
|
283
|
-
- eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
|
284
|
-
- eitil_wrapper/lib/eitil_wrapper/jobs/single_method_job.rb
|
285
|
-
- eitil_wrapper/lib/eitil_wrapper/railtie.rb
|
286
|
-
- eitil_wrapper/lib/eitil_wrapper/records.rb
|
287
|
-
- eitil_wrapper/lib/eitil_wrapper/records/default_calculators.rb
|
288
|
-
- eitil_wrapper/lib/eitil_wrapper/records/default_scopes.rb
|
289
|
-
- eitil_wrapper/lib/eitil_wrapper/records/default_sorts.rb
|
290
|
-
- eitil_wrapper/lib/eitil_wrapper/request_logger.rb
|
291
|
-
- eitil_wrapper/lib/eitil_wrapper/request_logger/controller_mixin.rb
|
292
|
-
- eitil_wrapper/lib/eitil_wrapper/request_logger/logger_job.rb
|
293
|
-
- eitil_wrapper/lib/eitil_wrapper/routes.rb
|
294
|
-
- eitil_wrapper/lib/eitil_wrapper/routes/extended_resources.rb
|
295
274
|
- lib/eitil.rb
|
296
275
|
- lib/eitil/all.rb
|
297
276
|
- lib/eitil/railtie.rb
|
@@ -309,9 +288,6 @@ files:
|
|
309
288
|
- spec/dummy_app/app/controllers/addresses_controller.rb
|
310
289
|
- spec/dummy_app/app/controllers/application_controller.rb
|
311
290
|
- spec/dummy_app/app/controllers/users_controller.rb
|
312
|
-
- spec/dummy_app/app/decorators/address_decorator.rb
|
313
|
-
- spec/dummy_app/app/decorators/application_decorator.rb
|
314
|
-
- spec/dummy_app/app/decorators/user_decorator.rb
|
315
291
|
- spec/dummy_app/app/helpers/addresses_helper.rb
|
316
292
|
- spec/dummy_app/app/helpers/application_helper.rb
|
317
293
|
- spec/dummy_app/app/helpers/users_helper.rb
|
@@ -444,7 +420,6 @@ files:
|
|
444
420
|
- spec/eitil_integrate/application_exporter/auto_sum_spec.rb
|
445
421
|
- spec/eitil_integrate/application_exporter/initialize_spec.rb
|
446
422
|
- spec/eitil_wrapper/callbacks/helper_methods_spec.rb
|
447
|
-
- spec/eitil_wrapper/decorators/decorators_spec.rb
|
448
423
|
- spec/eitil_wrapper/jobs/single_method_job_spec.rb
|
449
424
|
- spec/eitil_wrapper/routes/extended_resources_spec.rb
|
450
425
|
- spec/eitil_wrapper/scopes/default_scopes_spec.rb
|
data/eitil_wrapper/README.md
DELETED
@@ -1,309 +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::Decorators
|
41
|
-
|
42
|
-
```ruby
|
43
|
-
|
44
|
-
require "eitil_wrapper/decorators"
|
45
|
-
|
46
|
-
```
|
47
|
-
|
48
|
-
The Eitil decorator wrappers help you to standardize the calling of the right decorator method from within your controller action. Basically it provides you with a decorate macro in each controller.
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
decorate(dec_item, dec_method: nil, dec_class: nil, **dec_kwargs)
|
52
|
-
```
|
53
|
-
|
54
|
-
- dec_item is the instance that will be decorated
|
55
|
-
- dec_method enabled you to set the desired decorator method. If not provided, it will look into the request params: if params["isMobile"] is present it will call .app, if params["isWeb"] is present it will call :app. If neither is provided in the params, it will call the default method :base.
|
56
|
-
- dec_class enables you to overwrite the decorator class that will be called. If not provided, the decorator class will be inferred from the instance model's classname (User => UserDecorator).
|
57
|
-
- dec_kwargs enables you to provide additional arguments, which will be passed to your decorator method.
|
58
|
-
|
59
|
-
|
60
|
-
### Configuration
|
61
|
-
|
62
|
-
1. Your decorator classes should inherit from EitilWrapper::ApplicationDecorator.
|
63
|
-
2. Your controllers should inherit the module EitilWrapper::ControllerDecorator, through inclusion in a superclass.
|
64
|
-
3. If you set controller ivars for each request, you can make them available in your decorators by providing Eitil with the names of your ivars as an array of symbols:
|
65
|
-
|
66
|
-
```ruby
|
67
|
-
# initializers/eitil.rb
|
68
|
-
|
69
|
-
Eitil.set_config do |config|
|
70
|
-
config.controller_ivars = [:user, :env]
|
71
|
-
end
|
72
|
-
```
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
## EitilWrapper::Jobs
|
79
|
-
|
80
|
-
```ruby
|
81
|
-
|
82
|
-
require "eitil_wrapper/jobs"
|
83
|
-
|
84
|
-
```
|
85
|
-
|
86
|
-
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.
|
87
|
-
|
88
|
-
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.
|
89
|
-
|
90
|
-
In contrast, the new_job_now macro defines a new :method_job_now method, which performs in the foreground.
|
91
|
-
|
92
|
-
```ruby
|
93
|
-
# require "eitil_wrapper/jobs/new_job"
|
94
|
-
|
95
|
-
new_job(_method, *args, **kwargs)
|
96
|
-
# assuming a method :hello_world, call as: new_job :hello_world
|
97
|
-
# => defines :hello_world_job
|
98
|
-
```
|
99
|
-
|
100
|
-
```ruby
|
101
|
-
# require "eitil_wrapper/jobs/new_job_now"
|
102
|
-
|
103
|
-
new_job_now(_method, *args, **kwargs)
|
104
|
-
# assuming a method :hello_world, call as: new_job_now :hello_world
|
105
|
-
# => defines :hello_world_job_now
|
106
|
-
```
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
## EitilWrapper::Routes
|
113
|
-
|
114
|
-
```ruby
|
115
|
-
|
116
|
-
require "eitil_wrapper/routes"
|
117
|
-
|
118
|
-
```
|
119
|
-
|
120
|
-
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.
|
121
|
-
|
122
|
-
### New route
|
123
|
-
|
124
|
-
The first macro, .new_route, enables you to create new route objects which may be called and used by different controllers.
|
125
|
-
|
126
|
-
```ruby
|
127
|
-
# require "eitil_wrapper/routes/extended_resources"
|
128
|
-
|
129
|
-
new_route(verb, _method, action, scope)
|
130
|
-
# call as: new_route :post, :attachment, "add_attachment", :member
|
131
|
-
```
|
132
|
-
|
133
|
-
- verb refers to the http_verb, e.g. :put.
|
134
|
-
- 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.
|
135
|
-
- action refers to the controller action to which you want to redirect to request, e.g. :update_user.
|
136
|
-
- scope refers to the url and can be set to either :member or :collection.
|
137
|
-
|
138
|
-
### Add route
|
139
|
-
|
140
|
-
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.
|
141
|
-
|
142
|
-
```ruby
|
143
|
-
# require "eitil_wrapper/routes/extended_resources"
|
144
|
-
|
145
|
-
extended_resources(controller, **kwargs)
|
146
|
-
# call as: extended_resources :posts, only: [:create, :update, :attachment]
|
147
|
-
```
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
## EitilWrapper::Records
|
154
|
-
|
155
|
-
```ruby
|
156
|
-
|
157
|
-
# include all below EitilWrapper::Records helpers through:
|
158
|
-
require "eitil_wrapper/records"
|
159
|
-
|
160
|
-
```
|
161
|
-
|
162
|
-
### Scopes
|
163
|
-
|
164
|
-
```ruby
|
165
|
-
|
166
|
-
require "eitil_wrapper/records/scopes"
|
167
|
-
|
168
|
-
```
|
169
|
-
|
170
|
-
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:
|
171
|
-
|
172
|
-
```ruby
|
173
|
-
# require "eitil_wrapper/scopes/default_scopes"
|
174
|
-
|
175
|
-
# columns of datatype: boolean
|
176
|
-
.{column_name}_true
|
177
|
-
.{column_name}_false
|
178
|
-
|
179
|
-
# columns of datatype: datetime
|
180
|
-
.{column_name}_today
|
181
|
-
.{column_name}_past
|
182
|
-
.{column_name}_future
|
183
|
-
.{column_name}_on_date(date)
|
184
|
-
.{column_name}_before_date(date)
|
185
|
-
.{column_name}_after_date(date)
|
186
|
-
.{column_name}_between_dates(start_date, end_date)
|
187
|
-
|
188
|
-
# columns of datatype: date
|
189
|
-
.{column_name}_today
|
190
|
-
.{column_name}_past
|
191
|
-
.{column_name}_future
|
192
|
-
.{column_name}_on_date(date)
|
193
|
-
.{column_name}_before_date(date)
|
194
|
-
.{column_name}_after_date(date)
|
195
|
-
.{column_name}_between_dates(start_date, end_date)
|
196
|
-
|
197
|
-
# columns of datatype: integer
|
198
|
-
.{column_name}_equal_to(number)
|
199
|
-
.{column_name}_lower_than(number)
|
200
|
-
.{column_name}_higher_than(number)
|
201
|
-
.{column_name}_between(min, max)
|
202
|
-
|
203
|
-
# columns of datatype: float
|
204
|
-
.{column_name}_equal_to(number)
|
205
|
-
.{column_name}_lower_than(number)
|
206
|
-
.{column_name}_higher_than(number)
|
207
|
-
.{column_name}_between(min, max)
|
208
|
-
```
|
209
|
-
|
210
|
-
### Sorts
|
211
|
-
|
212
|
-
|
213
|
-
```ruby
|
214
|
-
|
215
|
-
require "eitil_wrapper/records/sorts"
|
216
|
-
|
217
|
-
```
|
218
|
-
|
219
|
-
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:
|
220
|
-
|
221
|
-
```ruby
|
222
|
-
# require "eitil_wrapper/scopes/default_scopes"
|
223
|
-
|
224
|
-
# columns of datatype: datetime
|
225
|
-
.{column_name}_oldest_first
|
226
|
-
.{column_name}_newest_first
|
227
|
-
|
228
|
-
# columns of datatype: date
|
229
|
-
.{column_name}_oldest_first
|
230
|
-
.{column_name}_newest_first
|
231
|
-
|
232
|
-
# columns of datatype: integer
|
233
|
-
.{column_name}_ascending
|
234
|
-
.{column_name}_descending
|
235
|
-
|
236
|
-
# columns of datatype: float
|
237
|
-
.{column_name}_ascending
|
238
|
-
.{column_name}_descending
|
239
|
-
```
|
240
|
-
|
241
|
-
|
242
|
-
### Calculators
|
243
|
-
|
244
|
-
|
245
|
-
```ruby
|
246
|
-
|
247
|
-
require "eitil_wrapper/records/calculators"
|
248
|
-
|
249
|
-
```
|
250
|
-
|
251
|
-
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:
|
252
|
-
|
253
|
-
```ruby
|
254
|
-
# require "eitil_wrapper/scopes/default_scopes"
|
255
|
-
|
256
|
-
# columns of datatype: array (serialized)
|
257
|
-
.{column_name}_sum # returns all uniq elements in a new, single array
|
258
|
-
.{column_name}_sum_i # sum and map to integer
|
259
|
-
.{column_name}_sum_f # sum and map to float
|
260
|
-
.{column_name}_sum_d # sum and map to decimal
|
261
|
-
|
262
|
-
# columns of datatype: integer
|
263
|
-
.{column_name}_max
|
264
|
-
.{column_name}_min
|
265
|
-
.{column_name}_sum
|
266
|
-
.{column_name}_avg
|
267
|
-
|
268
|
-
# columns of datatype: float
|
269
|
-
.{column_name}_max
|
270
|
-
.{column_name}_min
|
271
|
-
.{column_name}_sum
|
272
|
-
.{column_name}_avg
|
273
|
-
|
274
|
-
# columns of datatype: decimal
|
275
|
-
.{column_name}_max
|
276
|
-
.{column_name}_min
|
277
|
-
.{column_name}_sum
|
278
|
-
.{column_name}_avg
|
279
|
-
|
280
|
-
# columns of datatype: bigint
|
281
|
-
.{column_name}_max
|
282
|
-
.{column_name}_min
|
283
|
-
.{column_name}_sum
|
284
|
-
.{column_name}_avg
|
285
|
-
```
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
## EitilWrapper::RequestLogger
|
290
|
-
|
291
|
-
```ruby
|
292
|
-
|
293
|
-
require "eitil_wrapper/request_logger"
|
294
|
-
|
295
|
-
```
|
296
|
-
|
297
|
-
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.
|
298
|
-
|
299
|
-
```ruby
|
300
|
-
|
301
|
-
include EitilWrapper::RequestLogger::ControllerMixin
|
302
|
-
before_action :log_request
|
303
|
-
|
304
|
-
```
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
@@ -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,22 +0,0 @@
|
|
1
|
-
|
2
|
-
require "active_model/railtie"
|
3
|
-
|
4
|
-
module EitilWrapper
|
5
|
-
class ApplicationDecorator
|
6
|
-
|
7
|
-
include ActiveModel::Model
|
8
|
-
|
9
|
-
def initialize(attributes={}, **kwargs)
|
10
|
-
super attributes
|
11
|
-
all_kwargs_to_ivars binding
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.method_missing(method_name, *args, **kwargs)
|
15
|
-
if %i$ web app $.include?(method_name.to_sym)
|
16
|
-
kwargs.any? ? send(:base, *args, **kwargs) : send(:base, *args)
|
17
|
-
end
|
18
|
-
super
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|