eitil 0.3.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -277
- data/lib/eitil.rb +1 -1
- data/lib/eitil/all.rb +15 -0
- data/lib/eitil/engine.rb +24 -0
- data/lib/eitil/railtie.rb +6 -0
- data/lib/eitil/version.rb +3 -1
- metadata +15 -27
- data/app/controllers/eitil/application_controller.rb +0 -4
- data/app/jobs/eitil/application_job.rb +0 -4
- data/app/mailers/eitil/application_mailer.rb +0 -6
- data/app/models/eitil/application_record.rb +0 -5
- data/config/initializers/modules/dir.rb +0 -21
- data/config/initializers/monkeys/application_controller.rb +0 -14
- data/config/initializers/monkeys/application_record.rb +0 -16
- data/config/initializers/monkeys/date_time.rb +0 -7
- data/config/initializers/monkeys/hash.rb +0 -14
- data/config/initializers/monkeys/kernel.rb +0 -48
- data/config/initializers/monkeys/module.rb +0 -12
- data/config/initializers/monkeys/object.rb +0 -29
- data/config/initializers/wrappers/decorators/application_decorator.rb +0 -19
- data/config/initializers/wrappers/decorators/controller_decorator.rb +0 -63
- data/config/initializers/wrappers/jobs/active_job_macros.rb +0 -52
- data/config/initializers/wrappers/jobs/single_method_job.rb +0 -24
- data/config/initializers/wrappers/routes/extended_resources.rb +0 -40
- data/config/initializers/wrappers/scopes/default_scopes.rb +0 -83
- data/config/routes.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 948d1a4c6670e9303e5aa9ded5b56d71380ab4ee9cd7d0844e730d53675d89bc
|
4
|
+
data.tar.gz: 75cbdecdefb045078212de2861e722d24586931008a7a2b30aa60bc7a602eea3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a2ad8a88a1a978cc4599dc42e8368683ee7f00d31cbfc2618817fc3c14ac686bc013b493f75e9de2511ca65c1c755e7cdd3449a5d67215997a17e83871182a4
|
7
|
+
data.tar.gz: bfa3367d30a515c5f95a3643100f3d14e13704cf70d9391af919075fd922fc9d44fb8717edc5fdc62cc045d66c08b905205f8d7e4e018b6a60b3e4d4b4d83552
|
data/README.md
CHANGED
@@ -1,338 +1,100 @@
|
|
1
1
|
|
2
2
|
|
3
3
|
|
4
|
-
# Eitil
|
4
|
+
# Eitil
|
5
5
|
|
6
|
-
|
6
|
+
Eitil (eitje utility) never stops increasing your life's efficacy and productivity, yay!
|
7
7
|
|
8
|
+
Our gem currently exists of five seperate layers (Railties), which can be integrated as standalone gems. This design is very much like that of rails, thus affinity with integrating rails should make eitil feel familiar.
|
8
9
|
|
9
10
|
|
10
|
-
##
|
11
|
-
|
12
|
-
Add this line to your application's Gemfile:
|
13
|
-
|
14
|
-
```ruby
|
15
|
-
|
16
|
-
gem 'eitil' # check the latest version on https://rubygems.org/gems/eitil
|
17
|
-
|
18
|
-
```
|
19
|
-
|
20
|
-
Or, if you want a specific branch (requires auth for private branch):
|
21
|
-
|
22
|
-
```ruby
|
23
|
-
|
24
|
-
gem 'eitil', git: 'https://github.com/eitje-app/eitil_engine', branch: 'production'
|
25
|
-
|
26
|
-
```
|
27
|
-
|
28
|
-
Or, for development purposes:
|
29
|
-
|
30
|
-
```ruby
|
31
|
-
|
32
|
-
gem 'eitil', path: "/Users/jurriaanschrofer/Documents/eitil"
|
33
|
-
|
34
|
-
```
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
# Monkey patches
|
39
|
-
|
40
|
-
|
11
|
+
## Layers
|
41
12
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
# call as: all_args_to_ivars binding
|
48
|
-
|
49
|
-
args_to_ivars(binding, *local_vars)
|
50
|
-
# sets specified keywords arguments of the method's local binding to instance variables
|
51
|
-
# call as: all_args_to_ivars binding :user_id, :user_name
|
52
|
-
|
53
|
-
all_kwargs_to_ivars(local_binding, namespace=:kwargs)
|
54
|
-
# sets the method's **kwargs argument to instance variables, with each key as the ivar's "@#{name}" and the value as its value
|
55
|
-
# call as: kwargs_to_ivars binding
|
56
|
-
# the keywords container name can be overwritten, e.g. the common :attributes
|
57
|
-
|
58
|
-
set_ivars(*ivars)
|
59
|
-
# sets instance variables named @"#{ivar}" for each symbol passed, by invoking send("set_#{ivar}")
|
60
|
-
# e.g. set_ivars(:user) sets @user with the value returned by your local method .set_user
|
61
|
-
# call as: set_ivars :user, :authentication, :connection
|
62
|
-
|
63
|
-
run_validations(*validations)
|
64
|
-
# calls a method for each argument, namespaced as "validate_#{argument}"
|
65
|
-
# call as: run_validations(:single_receipt, :single_order)
|
66
|
-
# => calls #validate_single_receipt and #validate_single_order
|
67
|
-
|
68
|
-
safe_send(method, *args, return_value: nil)
|
69
|
-
# a safe version of .send, which in case of an error rescues and returns return_value (default: nil) instead
|
70
|
-
|
71
|
-
safe_call(*args, return_value: nil, &block)
|
72
|
-
# a safe version of .call, which in case of an error rescues and returns return_value (default: nil) instead
|
73
|
-
# accepts either a proc argument or a block
|
74
|
-
|
75
|
-
raise_error(_class_name, message = nil)
|
76
|
-
# creates an error class if currently undefined, inheriting from StandardError, and raises the error with the given message
|
77
|
-
# call as: raise_error "SomethingWentWrongError", "check your code, bro!"
|
78
|
-
# => SomethingWentWrongError (check your code, bro!)
|
79
|
-
```
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
## Object
|
84
|
-
|
85
|
-
```ruby
|
86
|
-
all_methods(include_ancestors = true, grep: nil)
|
87
|
-
# pretty prints all methods for any object, grouped per type (e.g. private_methods, public_instance_methods)
|
88
|
-
# call as: Class.all_methods false, grep: /json/
|
89
|
-
```
|
13
|
+
- EitilCore, [docs](/eitil_core) > extends the core classes of Ruby and rails.
|
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
|
+
- EitilStore, [docs](/eitil_store) > stores data in containers, such as Regexp instances.
|
17
|
+
- EitilIntegrate, [docs](/eitil_integrate) > provides seamless integrations with select gems and API's, through helper methods stored in PORO's.
|
90
18
|
|
91
19
|
|
92
20
|
|
93
|
-
##
|
21
|
+
## Cherry picking utilities
|
94
22
|
|
95
|
-
|
96
|
-
include_concerns_of(*directories, namespace: nil)
|
97
|
-
# includes models/concerns/{directories}/* if no namespace if given, or all concerns within the given namespace
|
98
|
-
# call as: include_concerns_of :user, :mail
|
99
|
-
# => includes all modules of models/concerns/user/* and models/oncerns/mail/*
|
100
|
-
# or call as: include_concerns_of :request_service, namespace: Eivid::Concerns
|
101
|
-
# tip: call Class.included_modules to view all included modules
|
102
|
-
```
|
23
|
+
Eitil has an extremely modular setup, which gives you fine-grained control over which monkey patches and rails wrappers you want to include into your project. Going from fine to coarse, there are 4 levels on which you can integrate eitil within your project:
|
103
24
|
|
104
25
|
|
26
|
+
### 1. include a single method
|
105
27
|
|
106
|
-
|
28
|
+
Almost each eitil method has it's own file, which you can easily require by it's path. To make things easy, both the docs and source code of the given method specify which path you should require.
|
107
29
|
|
108
30
|
```ruby
|
109
|
-
auto_dig(_hash = self, _key)
|
110
|
-
# finds the value for the given hash key, irregardless of the amount of nested layers
|
111
|
-
# call as: {a: 1, b: {c: 2, d: {e: 3}}}.auto_dig :e
|
112
|
-
# => 3
|
113
|
-
```
|
114
31
|
|
32
|
+
require "eitil_core/hash/auto_dig"
|
115
33
|
|
34
|
+
# This will simply add the patched Hash#auto_dig into your main application.
|
116
35
|
|
117
|
-
## ApplicationController
|
118
|
-
|
119
|
-
```ruby
|
120
|
-
slice_params(*args)
|
121
|
-
# slices request params, converts them to JSON and symbolizes the keys
|
122
|
-
# call as: slice_params :id, :user
|
123
|
-
# => { id: 1, user: 69 }
|
124
36
|
```
|
125
37
|
|
126
38
|
|
39
|
+
### 2. include a collection of methods
|
127
40
|
|
128
|
-
|
41
|
+
All single method files are combined into collections, which you can efficiently include at once. For example, the previous auto_dig method can also be included by:
|
129
42
|
|
130
43
|
```ruby
|
131
|
-
self.all_associations
|
132
|
-
# returns all associations for a given model
|
133
|
-
# call as: Environment.all_associations
|
134
|
-
```
|
135
44
|
|
45
|
+
require "eitil_core/hash"
|
136
46
|
|
47
|
+
# This will add all Hash patches into your project.
|
137
48
|
|
138
|
-
## DateTime
|
139
|
-
|
140
|
-
```ruby
|
141
|
-
prettify
|
142
|
-
# formats DateTime instances into a pretty, simple and filename friendly format
|
143
|
-
# call as: DateTime.now.prettify
|
144
|
-
# => "2021-04-21.17:51:42"
|
145
49
|
```
|
146
50
|
|
147
51
|
|
52
|
+
### 3. include a whole layer
|
148
53
|
|
149
|
-
|
150
|
-
|
54
|
+
A whole layer, for example all utilities provided by EitilCore, can be included at once in your application.rb file:
|
151
55
|
|
152
56
|
|
153
|
-
## Decorators
|
154
|
-
|
155
|
-
### Info
|
156
|
-
|
157
|
-
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.
|
158
|
-
|
159
|
-
### Decorate Macro
|
160
|
-
|
161
57
|
```ruby
|
162
|
-
decorate(dec_item, dec_method: nil, dec_class: nil, **dec_kwargs)
|
163
|
-
```
|
164
|
-
|
165
|
-
- dec_item is the instance that will be decorated
|
166
|
-
- 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.
|
167
|
-
- 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).
|
168
|
-
- dec_kwargs enables you to provide additional arguments, which will be passed to your decorator method.
|
169
58
|
|
170
|
-
|
59
|
+
# config/application.rb
|
171
60
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
```ruby
|
177
|
-
# initializers/eitil.rb
|
178
|
-
|
179
|
-
Eitil.set_config do |config|
|
180
|
-
config.get_controller_ivars_method = 'API::BaseController.controller_ivars' # => [:user, :env]
|
61
|
+
module MyApplication
|
62
|
+
class Application < Rails::Application
|
63
|
+
require 'eitil/eitil_core'
|
64
|
+
end
|
181
65
|
end
|
66
|
+
|
182
67
|
```
|
183
68
|
|
184
69
|
|
185
70
|
|
186
|
-
|
187
|
-
|
188
|
-
### Info
|
189
|
-
|
190
|
-
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.
|
191
|
-
|
192
|
-
### Create New Route Macro
|
193
|
-
|
194
|
-
The first macro, new_route, enables you to create new route objects which may be called and used by different controllers.
|
195
|
-
|
196
|
-
```ruby
|
197
|
-
# config/routes.rb
|
198
|
-
|
199
|
-
new_route(verb, _method, action, scope)
|
200
|
-
# call as: new_route :post, :attachment, "add_attachment", :member
|
201
|
-
```
|
202
|
-
|
203
|
-
- verb refers to the http_verb, e.g. :put.
|
204
|
-
- 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.
|
205
|
-
- action refers to the controller action to which you want to redirect to request, e.g. :update_user.
|
206
|
-
- scope refers to the url and can be set to either :member or :collection.
|
71
|
+
### 4. include all alyers
|
207
72
|
|
208
|
-
|
73
|
+
Just like you can include a single eitil layer, you can also include them all at once:
|
209
74
|
|
210
|
-
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.
|
211
75
|
|
212
76
|
```ruby
|
213
|
-
# config/routes.rb
|
214
77
|
|
215
|
-
|
216
|
-
# call as: extended_resources :posts, only: [:create, :update, :attachment]
|
217
|
-
|
218
|
-
```
|
219
|
-
|
220
|
-
### Configuration
|
221
|
-
|
222
|
-
The router wrapper is a single module which is automatically included into your application's router file, therefore no configuration is required.
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
## Jobs
|
227
|
-
|
228
|
-
### Info
|
229
|
-
|
230
|
-
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. 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. In contrast, the new_job_debugger macro defines a new :method_job_debugger method, which performs in the foreground.
|
231
|
-
|
232
|
-
### Job Macro
|
233
|
-
|
234
|
-
```ruby
|
235
|
-
new_job(_method, *args, **kwargs)
|
236
|
-
# assuming a method :hello_world, call as: new_job :hello_world
|
237
|
-
# => defines :hello_world_job
|
78
|
+
# config/application.rb
|
238
79
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
### Configuration
|
247
|
-
|
248
|
-
The new_job macro is monkey patched into Kernel, therefore no configuration is required.
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
## Scopes
|
253
|
-
|
254
|
-
### Info
|
255
|
-
|
256
|
-
The Eitil scopes wrapper creates various default scopes for a model.
|
257
|
-
|
258
|
-
### The Scopes
|
259
|
-
|
260
|
-
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:
|
261
|
-
|
262
|
-
```ruby
|
263
|
-
# columns of datatype: boolean
|
264
|
-
.{column_name}_true
|
265
|
-
.{column_name}_false
|
266
|
-
|
267
|
-
# columns of datatype: datetime
|
268
|
-
.{column_name}_today
|
269
|
-
.{column_name}_past
|
270
|
-
.{column_name}_future
|
271
|
-
.{column_name}_on_date(date)
|
272
|
-
.{column_name}_before_date(date)
|
273
|
-
.{column_name}_after_date(date)
|
274
|
-
.{column_name}_between_dates(start_date, end_date)
|
275
|
-
.{column_name}_oldest_first
|
276
|
-
.{column_name}_newest_first
|
277
|
-
|
278
|
-
# columns of datatype: date
|
279
|
-
.{column_name}_today
|
280
|
-
.{column_name}_past
|
281
|
-
.{column_name}_future
|
282
|
-
.{column_name}_on_date(date)
|
283
|
-
.{column_name}_before_date(date)
|
284
|
-
.{column_name}_after_date(date)
|
285
|
-
.{column_name}_between_dates(start_date, end_date)
|
286
|
-
.{column_name}_oldest_first
|
287
|
-
.{column_name}_newest_first
|
288
|
-
|
289
|
-
# columns of datatype: integer
|
290
|
-
.{column_name}_equal_to(number)
|
291
|
-
.{column_name}_lower_than(number)
|
292
|
-
.{column_name}_higher_than(number)
|
293
|
-
.{column_name}_between(min, max)
|
294
|
-
.{column_name}_ascending
|
295
|
-
.{column_name}_descending
|
296
|
-
|
297
|
-
# columns of datatype: float
|
298
|
-
.{column_name}_equal_to(number)
|
299
|
-
.{column_name}_lower_than(number)
|
300
|
-
.{column_name}_higher_than(number)
|
301
|
-
.{column_name}_between(min, max)
|
302
|
-
.{column_name}_ascending
|
303
|
-
.{column_name}_descending
|
80
|
+
module MyApplication
|
81
|
+
class Application < Rails::Application
|
82
|
+
require 'eitil/all'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
304
86
|
```
|
305
87
|
|
306
|
-
### Configuration
|
307
|
-
|
308
|
-
Your models should inherit the module Eitil::DefaultScopes through inclusion in a superclass, such as ApplicationRecord.
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
# Modules
|
313
88
|
|
314
89
|
|
315
90
|
|
316
|
-
##
|
317
|
-
|
318
|
-
### Info
|
319
|
-
|
320
|
-
The Eitil::Dir module provides methods which help you introspect your Rails project.
|
91
|
+
## Installation
|
321
92
|
|
322
|
-
|
93
|
+
Add eitil to your gemfile:
|
323
94
|
|
324
95
|
```ruby
|
325
|
-
Eitil::Dir.contents(directory='app')
|
326
|
-
# returns all files and subdirectories of a given directory
|
327
96
|
|
328
|
-
|
329
|
-
# returns all files of a given directory
|
97
|
+
gem 'eitil', '1.0.0' # check the latest version on https://rubygems.org/gems/eitil
|
330
98
|
|
331
|
-
Eitil::Dir.subdirs(directory='app')
|
332
|
-
# returns all subdirectories of a given directory
|
333
|
-
|
334
|
-
Eitil::Dir.lines(directory='app')
|
335
|
-
# returns the total amount of lines of all files of a given directory
|
336
99
|
```
|
337
100
|
|
338
|
-
|
data/lib/eitil.rb
CHANGED
data/lib/eitil/all.rb
ADDED
data/lib/eitil/engine.rb
CHANGED
@@ -1,8 +1,32 @@
|
|
1
|
+
|
2
|
+
require 'eitil/railtie'
|
3
|
+
|
4
|
+
|
5
|
+
# Constants
|
6
|
+
|
1
7
|
module Eitil
|
2
8
|
|
9
|
+
# preferably find a less hacky way to retrieve the gem's root path, perhaps with Kernel#pwd?
|
10
|
+
Root = $LOAD_PATH.find { |x| x.match /eitil/ }.chomp('/lib')
|
11
|
+
Layers = %w( eitil_core eitil_support eitil_wrapper eitil_store eitil_integrate )
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
# Configuration
|
17
|
+
|
18
|
+
module Eitil
|
19
|
+
|
3
20
|
class Engine < ::Rails::Engine
|
21
|
+
|
4
22
|
isolate_namespace Eitil
|
5
23
|
config.generators.api_only = true
|
24
|
+
|
25
|
+
# Add lib dirs to $LOAD_PATH, making them available in your main app.
|
26
|
+
Eitil::Layers.each do |layer|
|
27
|
+
$LOAD_PATH << "#{Eitil::Root}/#{layer}/lib"
|
28
|
+
end
|
29
|
+
|
6
30
|
end
|
7
31
|
|
8
32
|
mattr_accessor :get_controller_ivars_method
|
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: 0.
|
4
|
+
version: 1.0.0
|
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-06-
|
11
|
+
date: 2021-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,7 +38,11 @@ dependencies:
|
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.9.2
|
41
|
-
description:
|
41
|
+
description: "Eitil (eitje utility) never stops increasing your life's efficacy and
|
42
|
+
productivity, yay!\n Our gem currently exists of five seperate
|
43
|
+
layers (Railties), which can be integrated as standalone gems. \n This
|
44
|
+
design is very much like that of rails, thus affinity with integrating rails should
|
45
|
+
make eitil feel familiar."
|
42
46
|
email:
|
43
47
|
- jschrofer@gmail.com
|
44
48
|
executables: []
|
@@ -48,36 +52,19 @@ files:
|
|
48
52
|
- MIT-LICENSE
|
49
53
|
- README.md
|
50
54
|
- Rakefile
|
51
|
-
- app/controllers/eitil/application_controller.rb
|
52
|
-
- app/jobs/eitil/application_job.rb
|
53
|
-
- app/mailers/eitil/application_mailer.rb
|
54
|
-
- app/models/eitil/application_record.rb
|
55
|
-
- config/initializers/modules/dir.rb
|
56
|
-
- config/initializers/monkeys/application_controller.rb
|
57
|
-
- config/initializers/monkeys/application_record.rb
|
58
|
-
- config/initializers/monkeys/date_time.rb
|
59
|
-
- config/initializers/monkeys/hash.rb
|
60
|
-
- config/initializers/monkeys/kernel.rb
|
61
|
-
- config/initializers/monkeys/module.rb
|
62
|
-
- config/initializers/monkeys/object.rb
|
63
|
-
- config/initializers/wrappers/decorators/application_decorator.rb
|
64
|
-
- config/initializers/wrappers/decorators/controller_decorator.rb
|
65
|
-
- config/initializers/wrappers/jobs/active_job_macros.rb
|
66
|
-
- config/initializers/wrappers/jobs/single_method_job.rb
|
67
|
-
- config/initializers/wrappers/routes/extended_resources.rb
|
68
|
-
- config/initializers/wrappers/scopes/default_scopes.rb
|
69
|
-
- config/routes.rb
|
70
55
|
- lib/eitil.rb
|
56
|
+
- lib/eitil/all.rb
|
71
57
|
- lib/eitil/engine.rb
|
58
|
+
- lib/eitil/railtie.rb
|
72
59
|
- lib/eitil/version.rb
|
73
60
|
- lib/tasks/eitil_tasks.rake
|
74
|
-
homepage: https://eitje
|
61
|
+
homepage: https://github.com/eitje-app/eitil_engine
|
75
62
|
licenses:
|
76
63
|
- MIT
|
77
64
|
metadata:
|
78
|
-
homepage_uri: https://eitje
|
79
|
-
source_code_uri: https://eitje
|
80
|
-
changelog_uri: https://eitje
|
65
|
+
homepage_uri: https://github.com/eitje-app/eitil_engine
|
66
|
+
source_code_uri: https://github.com/eitje-app/eitil_engine
|
67
|
+
changelog_uri: https://github.com/eitje-app/eitil_engine
|
81
68
|
post_install_message:
|
82
69
|
rdoc_options: []
|
83
70
|
require_paths:
|
@@ -96,5 +83,6 @@ requirements: []
|
|
96
83
|
rubygems_version: 3.1.2
|
97
84
|
signing_key:
|
98
85
|
specification_version: 4
|
99
|
-
summary:
|
86
|
+
summary: Eitil (eitje utility) never stops increasing your life's efficacy and productivity,
|
87
|
+
yay!
|
100
88
|
test_files: []
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Eitil::Dir
|
2
|
-
class << self
|
3
|
-
|
4
|
-
def contents(directory='app')
|
5
|
-
Dir[File.join(directory, '**', '*')]
|
6
|
-
end
|
7
|
-
|
8
|
-
def files(directory='app')
|
9
|
-
contents(directory).select { |file| File.file?(file) }
|
10
|
-
end
|
11
|
-
|
12
|
-
def subdirs(directory='app')
|
13
|
-
contents(directory).select { |file| File.directory?(file) }
|
14
|
-
end
|
15
|
-
|
16
|
-
def lines(directory='app')
|
17
|
-
files(directory).map { |file| File.open(file).count }.sum
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module ApplicationControllerMonkey
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
included do
|
4
|
-
|
5
|
-
private
|
6
|
-
|
7
|
-
def slice_params(*args)
|
8
|
-
params.slice(*args).as_json.symbolize_keys
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
ApplicationController.send :include, ApplicationControllerMonkey
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require "#{Eitil::Engine.root.to_s}/config/initializers/wrappers/scopes/default_scopes.rb"
|
2
|
-
|
3
|
-
module ApplicationRecordMonkey
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
included do
|
6
|
-
|
7
|
-
def self.all_associations
|
8
|
-
reflect_on_all_associations.map do |assoc|
|
9
|
-
{ assoc.name => assoc.association_class.to_s.demodulize }
|
10
|
-
end.inject &:merge
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
ApplicationRecord.send :include, ApplicationRecordMonkey
|
@@ -1,48 +0,0 @@
|
|
1
|
-
Kernel.module_eval do
|
2
|
-
|
3
|
-
def all_args_to_ivars(local_binding)
|
4
|
-
local_binding.local_variables.each do |lvar|
|
5
|
-
instance_variable_set("@#{lvar}", local_binding.local_variable_get(lvar))
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
def args_to_ivars(local_binding, *local_vars)
|
10
|
-
local_vars.each do |lvar|
|
11
|
-
instance_variable_set("@#{lvar}", local_binding.local_variable_get(lvar))
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def all_kwargs_to_ivars(local_binding, namespace=:kwargs)
|
16
|
-
local_binding.local_variable_get(namespace).each do |name, value|
|
17
|
-
instance_variable_set "@#{name}", value
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def set_ivars(*ivars)
|
22
|
-
ivars.each do |ivar|
|
23
|
-
instance_variable_set("@#{ivar}", send("set_#{ivar}"))
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def run_validations(*validations)
|
28
|
-
validations.each { |v| eval "validate_#{v}" }
|
29
|
-
end
|
30
|
-
|
31
|
-
def safe_call(*args, return_value: nil, &block)
|
32
|
-
block.call self, *args
|
33
|
-
rescue
|
34
|
-
return_value
|
35
|
-
end
|
36
|
-
|
37
|
-
def safe_send(method, *args, return_value: nil)
|
38
|
-
self.send method, *args
|
39
|
-
rescue
|
40
|
-
return_value
|
41
|
-
end
|
42
|
-
|
43
|
-
def raise_error(_class_name, message = nil)
|
44
|
-
Object.const_set(_class_name, Class.new(StandardError)) unless Object.const_defined?(_class_name)
|
45
|
-
raise _class_name.constantize.new message
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
class Module
|
2
|
-
|
3
|
-
def include_concerns_of(*directories, namespace: nil)
|
4
|
-
directories.map! { |dir| "#{namespace}::#{dir.to_s.camelcase}" }
|
5
|
-
|
6
|
-
directories.each do |dir|
|
7
|
-
konstants = dir.constantize.constants(false)
|
8
|
-
konstants.each { |kon| include(const_get "#{dir}::#{kon}") }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require "awesome_print"
|
2
|
-
|
3
|
-
class Object
|
4
|
-
|
5
|
-
def all_methods(include_ancestors = true, grep: nil)
|
6
|
-
|
7
|
-
_introspection_methods = %i$
|
8
|
-
methods
|
9
|
-
singleton_methods
|
10
|
-
instance_methods
|
11
|
-
private_methods
|
12
|
-
public_methods
|
13
|
-
protected_methods
|
14
|
-
private_instance_methods
|
15
|
-
public_instance_methods
|
16
|
-
protected_instance_methods
|
17
|
-
$
|
18
|
-
|
19
|
-
_introspection_methods.map! do |_m|
|
20
|
-
_methods = safe_send _m, include_ancestors
|
21
|
-
_methods = grep ? _methods&.grep(grep) : _methods
|
22
|
-
{ _m => _methods }
|
23
|
-
end
|
24
|
-
|
25
|
-
ap _introspection_methods.inject &:merge
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Eitil
|
2
|
-
class ApplicationDecorator
|
3
|
-
|
4
|
-
include ActiveModel::Model
|
5
|
-
|
6
|
-
def initialize(attributes={}, **kwargs)
|
7
|
-
super attributes
|
8
|
-
all_kwargs_to_ivars binding
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.method_missing(method_name, *args, **kwargs)
|
12
|
-
if %i$ web app $.include?(method_name.to_sym)
|
13
|
-
kwargs.any? ? send(:base, *args, **kwargs) : send(:base, *args)
|
14
|
-
end
|
15
|
-
super
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module Eitil
|
2
|
-
module ControllerDecorator
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
included do
|
5
|
-
|
6
|
-
private
|
7
|
-
|
8
|
-
def decorate(dec_item, dec_method: nil, dec_class: nil, **dec_kwargs)
|
9
|
-
all_args_to_ivars binding
|
10
|
-
set_ivars :dec_class, :dec_method, :decorator
|
11
|
-
send_to_decorator
|
12
|
-
end
|
13
|
-
|
14
|
-
def send_to_decorator
|
15
|
-
@dec_kwargs.any? ? @decorator.send(@dec_method, @dec_item, @dec_kwargs)
|
16
|
-
: @decorator.send(@dec_method, @dec_item)
|
17
|
-
|
18
|
-
rescue NoMethodError => e
|
19
|
-
inform_no_method_for_decorator_error
|
20
|
-
@dec_item
|
21
|
-
end
|
22
|
-
|
23
|
-
def inform_no_method_for_decorator_error
|
24
|
-
message = "Warning: NoMethodError for #{@dec_class}.#{@dec_method}, returned @dec_item instead."
|
25
|
-
Logger.new("#{Rails.root}/log/decorator_log.log").warn message
|
26
|
-
warn message
|
27
|
-
end
|
28
|
-
|
29
|
-
def set_dec_method
|
30
|
-
@dec_method = @dec_method || derived_dec_method || :base
|
31
|
-
end
|
32
|
-
|
33
|
-
def derived_dec_method
|
34
|
-
return unless respond_to? :params
|
35
|
-
return :app if params["isMobile"]
|
36
|
-
return :web if params["isWeb"]
|
37
|
-
end
|
38
|
-
|
39
|
-
def set_dec_class
|
40
|
-
@dec_class = @dec_class ? manual_set_dec_class : derived_dec_class
|
41
|
-
end
|
42
|
-
|
43
|
-
def manual_set_dec_class
|
44
|
-
"#{@dec_class}Decorator".constantize
|
45
|
-
end
|
46
|
-
|
47
|
-
def derived_dec_class
|
48
|
-
"#{@dec_item.class.name}Decorator".constantize
|
49
|
-
end
|
50
|
-
|
51
|
-
def set_decorator
|
52
|
-
@decorator = @dec_class.new controller_ivars
|
53
|
-
end
|
54
|
-
|
55
|
-
def controller_ivars
|
56
|
-
eval(Eitil.get_controller_ivars_method).map do |ivar|
|
57
|
-
{ ivar => instance_variable_get("@#{ivar.to_s}") }
|
58
|
-
end.inject &:merge
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
Kernel.module_eval do
|
2
|
-
|
3
|
-
# BEWARE: _self is currently not accepted in perform_later jobs due to serialization errors
|
4
|
-
|
5
|
-
# The cases of 'id' and '_self' both handle instances, with the difference
|
6
|
-
# being that 'id' works for objects that have a database record, while '_self'
|
7
|
-
# works for non database supported instanes, such as an Exporter instance.
|
8
|
-
|
9
|
-
def new_job(_method, *args, **kwargs)
|
10
|
-
|
11
|
-
if instance_methods(false).include? _method
|
12
|
-
define_method "#{_method}_job" do |_self = nil, *args, **kwargs|
|
13
|
-
|
14
|
-
Eitil::SingleMethodJob.perform_later(
|
15
|
-
*args, _class: self.class.to_s, _method: _method.to_s, id: safe_send(:id), _self: self.to_json, **kwargs
|
16
|
-
)
|
17
|
-
end
|
18
|
-
|
19
|
-
elsif singleton_methods(false).include? _method
|
20
|
-
define_singleton_method "#{_method}_job" do |*args, **kwargs|
|
21
|
-
|
22
|
-
Eitil::SingleMethodJob.perform_later(
|
23
|
-
*args, _class: to_s, _method: _method.to_s, **kwargs
|
24
|
-
)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# BEWARE: This is an exact copy of the above method, except for .perform_now instead of .perform_later and the method's name.
|
30
|
-
# The reason for not using helper methods is to not unnecessarily fill and potentially fuck up the Kernel environment.
|
31
|
-
|
32
|
-
def new_job_debugger(_method, *args, **kwargs)
|
33
|
-
|
34
|
-
if instance_methods(false).include? _method
|
35
|
-
define_method "#{_method}_job_debugger" do |_self = nil, *args, **kwargs|
|
36
|
-
|
37
|
-
Eitil::SingleMethodJob.perform_now(
|
38
|
-
*args, _class: self.class.to_s, _method: _method.to_s, id: safe_send(:id), _self: self.to_json, **kwargs
|
39
|
-
)
|
40
|
-
end
|
41
|
-
|
42
|
-
elsif singleton_methods(false).include? _method
|
43
|
-
define_singleton_method "#{_method}_job_debugger" do |*args, **kwargs|
|
44
|
-
|
45
|
-
Eitil::SingleMethodJob.perform_now(
|
46
|
-
*args, _class: to_s, _method: _method.to_s, **kwargs
|
47
|
-
)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Eitil
|
2
|
-
class SingleMethodJob < ApplicationJob
|
3
|
-
queue_as :default
|
4
|
-
|
5
|
-
# BEWARE: _self is currently not accepted in perform_later jobs due to serialization errors
|
6
|
-
|
7
|
-
# The cases of 'id' and '_self' both handle instances, with the difference
|
8
|
-
# being that 'id' works for objects that have a database record, while '_self'
|
9
|
-
# works for non database supported instanes, such as an Exporter instance.
|
10
|
-
|
11
|
-
def perform(*args, _class:, _method:, id: nil, _self: nil, **kwargs)
|
12
|
-
object =
|
13
|
-
if id
|
14
|
-
_class.constantize.find(id)
|
15
|
-
elsif _self
|
16
|
-
_self
|
17
|
-
else
|
18
|
-
_class.constantize
|
19
|
-
end
|
20
|
-
|
21
|
-
object.send _method, *args, **kwargs
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Eitil
|
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, Eitil::ExtendedResources
|
@@ -1,83 +0,0 @@
|
|
1
|
-
module Eitil
|
2
|
-
module DefaultScopes
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
included do
|
5
|
-
class << self
|
6
|
-
|
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) }
|
16
|
-
|
17
|
-
_class.eitil_scope :"#{column}_oldest_first", -> { order("#{column} ASC") }
|
18
|
-
_class.eitil_scope :"#{column}_newest_first", -> { order("#{column} DESC") }
|
19
|
-
}
|
20
|
-
|
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) }
|
26
|
-
|
27
|
-
_class.eitil_scope :"#{column}_ascending", -> { order("#{column} ASC") }
|
28
|
-
_class.eitil_scope :"#{column}_descending", -> { order("#{column} DESC") }
|
29
|
-
}
|
30
|
-
|
31
|
-
def inherited(subclass)
|
32
|
-
super
|
33
|
-
subclass.use_eitil_scopes
|
34
|
-
end
|
35
|
-
|
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
|
40
|
-
|
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
|
48
|
-
|
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
|
54
|
-
end
|
55
|
-
|
56
|
-
def create_eitil_datetime_scopes
|
57
|
-
columns_of_type(:datetime)&.map do |column, object|
|
58
|
-
SharableDateScopes.call self, column
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def create_eitil_date_scopes
|
63
|
-
columns_of_type(:date)&.map do |column, object|
|
64
|
-
SharableDateScopes.call self, column
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def create_eitil_integer_scopes
|
69
|
-
columns_of_type(:integer)&.map do |column, object|
|
70
|
-
SharableNumScopes.call self, column
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def create_eitil_float_scopes
|
75
|
-
columns_of_type(:float)&.map do |column, object|
|
76
|
-
SharableNumScopes.call self, column
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
data/config/routes.rb
DELETED