eitil 0.3.10 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -331
  3. data/lib/eitil.rb +1 -1
  4. data/lib/eitil/all.rb +15 -0
  5. data/lib/eitil/engine.rb +24 -0
  6. data/lib/eitil/railtie.rb +6 -0
  7. data/lib/eitil/version.rb +3 -1
  8. metadata +15 -32
  9. data/app/controllers/eitil/application_controller.rb +0 -4
  10. data/app/jobs/eitil/application_job.rb +0 -4
  11. data/app/mailers/eitil/application_mailer.rb +0 -6
  12. data/app/models/eitil/application_record.rb +0 -5
  13. data/app/models/eitil/stack_trace/audit.rb +0 -15
  14. data/app/models/eitil/stack_trace/call.rb +0 -17
  15. data/app/models/eitil/stack_trace/stack.rb +0 -28
  16. data/config/initializers/modules/dir.rb +0 -21
  17. data/config/initializers/monkeys/application_controller.rb +0 -14
  18. data/config/initializers/monkeys/application_record.rb +0 -30
  19. data/config/initializers/monkeys/date_time.rb +0 -7
  20. data/config/initializers/monkeys/float.rb +0 -9
  21. data/config/initializers/monkeys/hash.rb +0 -14
  22. data/config/initializers/monkeys/kernel.rb +0 -48
  23. data/config/initializers/monkeys/module.rb +0 -12
  24. data/config/initializers/monkeys/object.rb +0 -29
  25. data/config/initializers/monkeys/string.rb +0 -96
  26. data/config/initializers/wrappers/decorators/application_decorator.rb +0 -19
  27. data/config/initializers/wrappers/decorators/controller_decorator.rb +0 -63
  28. data/config/initializers/wrappers/jobs/active_job_macros.rb +0 -52
  29. data/config/initializers/wrappers/jobs/single_method_job.rb +0 -24
  30. data/config/initializers/wrappers/routes/extended_resources.rb +0 -40
  31. data/config/initializers/wrappers/scopes/default_scopes.rb +0 -83
  32. data/config/routes.rb +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a5f03357f8feee5c40fa17fdf11acc544229eb85e822578929d18bab25f5ec4
4
- data.tar.gz: 32ecc96ed0088b7a447fac59505d76e1f5c0e4131b38a615b2ccdf6bdbdf4b13
3
+ metadata.gz: 948d1a4c6670e9303e5aa9ded5b56d71380ab4ee9cd7d0844e730d53675d89bc
4
+ data.tar.gz: 75cbdecdefb045078212de2861e722d24586931008a7a2b30aa60bc7a602eea3
5
5
  SHA512:
6
- metadata.gz: 706798e2c7e5e1f81cd413a5698fa030eedcc606dae5a2a6ade7fd74bc21cfa1e485cc3a7c782097aa7cac2271d879f91e8d0791627540df9acd03e8bc873273
7
- data.tar.gz: c33996734e261cc3419ad9dfcec4dd271ecb40be39cc0dac2ae44156f750329a179a3988ba0a4d574a27fa8d411b1542f230c566544d9bb67ef4f6c60d93dc1a
6
+ metadata.gz: 9a2ad8a88a1a978cc4599dc42e8368683ee7f00d31cbfc2618817fc3c14ac686bc013b493f75e9de2511ca65c1c755e7cdd3449a5d67215997a17e83871182a4
7
+ data.tar.gz: bfa3367d30a515c5f95a3643100f3d14e13704cf70d9391af919075fd922fc9d44fb8717edc5fdc62cc045d66c08b905205f8d7e4e018b6a60b3e4d4b4d83552
data/README.md CHANGED
@@ -1,392 +1,100 @@
1
1
 
2
2
 
3
3
 
4
- # Eitil (Eitje Util)
4
+ # Eitil
5
5
 
6
- Never stops increasing your life's efficacy and productivity, yay!
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
- ## Installation
11
-
12
- Add this line to your application's Gemfile:
11
+ ## Layers
13
12
 
14
- ```ruby
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.
15
18
 
16
- gem 'eitil' # check the latest version on https://rubygems.org/gems/eitil
17
19
 
18
- ```
19
20
 
20
- Or, if you want a specific branch (requires auth for private branch):
21
+ ## Cherry picking utilities
21
22
 
22
- ```ruby
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:
23
24
 
24
- gem 'eitil', git: 'https://github.com/eitje-app/eitil_engine', branch: 'production'
25
25
 
26
- ```
26
+ ### 1. include a single method
27
27
 
28
- Or, for development purposes:
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.
29
29
 
30
30
  ```ruby
31
31
 
32
- gem 'eitil', path: "/Users/jurriaanschrofer/Documents/eitil"
33
-
34
- ```
35
-
36
-
37
-
38
- # Monkey patches
39
-
32
+ require "eitil_core/hash/auto_dig"
40
33
 
34
+ # This will simply add the patched Hash#auto_dig into your main application.
41
35
 
42
- ## Kernel
43
-
44
- ```ruby
45
- all_args_to_ivars(binding)
46
- # sets all keywords arguments of the method's local binding to instance variables
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
36
  ```
80
37
 
81
38
 
39
+ ### 2. include a collection of methods
82
40
 
83
- ## Object
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:
84
42
 
85
43
  ```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
- ```
90
-
91
44
 
45
+ require "eitil_core/hash"
92
46
 
93
- ## Module
47
+ # This will add all Hash patches into your project.
94
48
 
95
- ```ruby
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
49
  ```
103
50
 
104
51
 
52
+ ### 3. include a whole layer
105
53
 
106
- ## String
107
-
108
- ```ruby
109
- is_num?
110
- # returns true if a string matches the Rubinius source code regex for strings and integers, false otherwise
111
- # comes in handy since ruby plays it safe on string to number conversion ('aaa'.to_f returns 0.0, thus is valid)
112
- # this method is also implemented for all other classes, such as Integer, Float, NilClass, TrueClass, Hash and so on...
113
-
114
- is_nan?
115
- # returns true if a string does NOT match the Rubinius source code regex for strings and integers, false otherwise
116
- # comes in handy since ruby plays it safe on string to number conversion ('aaa'.to_f returns 0.0, thus is valid)
117
- # this method is also implemented for all other classes, such as Integer, Float, NilClass, TrueClass, Hash and so on...
118
- ```
119
-
120
-
54
+ A whole layer, for example all utilities provided by EitilCore, can be included at once in your application.rb file:
121
55
 
122
- ## Hash
123
56
 
124
57
  ```ruby
125
- auto_dig(_hash = self, _key)
126
- # finds the value for the given hash key, irregardless of the amount of nested layers
127
- # call as: {a: 1, b: {c: 2, d: {e: 3}}}.auto_dig :e
128
- # => 3
129
- ```
130
-
131
-
132
-
133
- ## Float
134
-
135
- ```ruby
136
- safe_to_i
137
- # converts a float to an integer, only when no decimal values are lost.
138
- # 8.00.safe_to_i returns 8 (Integer)
139
- # 8.88.safe_to_i returns 8.88 (Float)
140
- ```
141
-
142
-
143
-
144
- ## ApplicationController
145
-
146
- ```ruby
147
- slice_params(*args)
148
- # slices request params, converts them to JSON and symbolizes the keys
149
- # call as: slice_params :id, :user
150
- # => { id: 1, user: 69 }
151
- ```
152
-
153
-
154
-
155
- ## ApplicationRecord
156
-
157
- ```ruby
158
- self.all_associations
159
- # returns all associations for a given model
160
- # call as: Environment.all_associations
161
-
162
- self.where_like(_hash)
163
- # runs .where with your string field made into a wildcard and case insensitive
164
- # call as: User.where_like(name: 'jurriaan')
165
-
166
- self.find_by_like(_hash)
167
- # runs .find_by with your string field made into a wildcard and case insensitive
168
- # call as: User.find_by_like(name: 'jurriaan')
169
- ```
170
-
171
-
172
-
173
- ## DateTime
174
-
175
- ```ruby
176
- prettify
177
- # formats DateTime instances into a pretty, simple and filename friendly format
178
- # call as: DateTime.now.prettify
179
- # => "2021-04-21.17:51:42"
180
- ```
181
-
182
-
183
-
184
- # Wrappers
185
-
186
-
187
-
188
- ## Decorators
189
-
190
- ### Info
191
-
192
- 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.
193
-
194
- ### Decorate Macro
195
-
196
- ```ruby
197
- decorate(dec_item, dec_method: nil, dec_class: nil, **dec_kwargs)
198
- ```
199
58
 
200
- - dec_item is the instance that will be decorated
201
- - 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.
202
- - 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).
203
- - dec_kwargs enables you to provide additional arguments, which will be passed to your decorator method.
59
+ # config/application.rb
204
60
 
205
- ### Configuration
206
-
207
- 1. Your decorator classes should inherit from Eitil::ApplicationDecorator.
208
- 2. Your controllers should inherit the module Eitil::ControllerDecorator, through inclusion in a superclass.
209
- 3. If you set controller ivars for each request, you can make them available in your decorators by providing Eitil a method which returns the names of your ivars as an array of symbols:
210
-
211
- ```ruby
212
- # initializers/eitil.rb
213
-
214
- Eitil.set_config do |config|
215
- 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
216
65
  end
66
+
217
67
  ```
218
68
 
219
69
 
220
70
 
221
- ## Router
222
-
223
- ### Info
224
-
225
- 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.
226
-
227
- ### Create New Route Macro
228
-
229
- The first macro, new_route, enables you to create new route objects which may be called and used by different controllers.
230
-
231
- ```ruby
232
- # config/routes.rb
233
-
234
- new_route(verb, _method, action, scope)
235
- # call as: new_route :post, :attachment, "add_attachment", :member
236
- ```
237
-
238
- - verb refers to the http_verb, e.g. :put.
239
- - 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.
240
- - action refers to the controller action to which you want to redirect to request, e.g. :update_user.
241
- - scope refers to the url and can be set to either :member or :collection.
242
-
243
- ### Add Routes Macro
244
-
245
- 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.
246
-
247
- ```ruby
248
- # config/routes.rb
249
-
250
- extended_resources(controller, **kwargs)
251
- # call as: extended_resources :posts, only: [:create, :update, :attachment]
252
-
253
- ```
254
-
255
- ### Configuration
256
-
257
- The router wrapper is a single module which is automatically included into your application's router file, therefore no configuration is required.
258
-
71
+ ### 4. include all alyers
259
72
 
73
+ Just like you can include a single eitil layer, you can also include them all at once:
260
74
 
261
- ## Jobs
262
-
263
- ### Info
264
-
265
- 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.
266
-
267
- ### Job Macro
268
75
 
269
76
  ```ruby
270
- new_job(_method, *args, **kwargs)
271
- # assuming a method :hello_world, call as: new_job :hello_world
272
- # => defines :hello_world_job
273
-
274
- new_job_debugger(_method, *args, **kwargs)
275
- # assuming a method :hello_world, call as: new_job_debugger :hello_world
276
- # => defines :hello_world_job_debugger
277
- ```
278
-
279
- - method is
280
-
281
- ### Configuration
282
77
 
283
- The new_job macro is monkey patched into Kernel, therefore no configuration is required.
78
+ # config/application.rb
284
79
 
285
-
286
-
287
- ## Scopes
288
-
289
- ### Info
290
-
291
- The Eitil scopes wrapper creates various default scopes for a model.
292
-
293
- ### The Scopes
294
-
295
- 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:
296
-
297
- ```ruby
298
- # columns of datatype: boolean
299
- .{column_name}_true
300
- .{column_name}_false
301
-
302
- # columns of datatype: datetime
303
- .{column_name}_today
304
- .{column_name}_past
305
- .{column_name}_future
306
- .{column_name}_on_date(date)
307
- .{column_name}_before_date(date)
308
- .{column_name}_after_date(date)
309
- .{column_name}_between_dates(start_date, end_date)
310
- .{column_name}_oldest_first
311
- .{column_name}_newest_first
312
-
313
- # columns of datatype: date
314
- .{column_name}_today
315
- .{column_name}_past
316
- .{column_name}_future
317
- .{column_name}_on_date(date)
318
- .{column_name}_before_date(date)
319
- .{column_name}_after_date(date)
320
- .{column_name}_between_dates(start_date, end_date)
321
- .{column_name}_oldest_first
322
- .{column_name}_newest_first
323
-
324
- # columns of datatype: integer
325
- .{column_name}_equal_to(number)
326
- .{column_name}_lower_than(number)
327
- .{column_name}_higher_than(number)
328
- .{column_name}_between(min, max)
329
- .{column_name}_ascending
330
- .{column_name}_descending
331
-
332
- # columns of datatype: float
333
- .{column_name}_equal_to(number)
334
- .{column_name}_lower_than(number)
335
- .{column_name}_higher_than(number)
336
- .{column_name}_between(min, max)
337
- .{column_name}_ascending
338
- .{column_name}_descending
80
+ module MyApplication
81
+ class Application < Rails::Application
82
+ require 'eitil/all'
83
+ end
84
+ end
85
+
339
86
  ```
340
87
 
341
- ### Configuration
342
-
343
- Your models should inherit the module Eitil::DefaultScopes through inclusion in a superclass, such as ApplicationRecord.
344
-
345
-
346
-
347
- # Modules & Classes
348
-
349
-
350
88
 
351
- ## Eitil::Dir
352
89
 
353
- ### Info
354
90
 
355
- The Eitil::Dir module provides methods which help you introspect your Rails project.
91
+ ## Installation
356
92
 
357
- ### Methods
93
+ Add eitil to your gemfile:
358
94
 
359
95
  ```ruby
360
- Eitil::Dir.contents(directory='app')
361
- # returns all files and subdirectories of a given directory
362
-
363
- Eitil::Dir.files(directory='app')
364
- # returns all files of a given directory
365
96
 
366
- Eitil::Dir.subdirs(directory='app')
367
- # returns all subdirectories of a given directory
97
+ gem 'eitil', '1.0.0' # check the latest version on https://rubygems.org/gems/eitil
368
98
 
369
- Eitil::Dir.lines(directory='app')
370
- # returns the total amount of lines of all files of a given directory
371
99
  ```
372
100
 
373
-
374
-
375
- ## Eitil::StackTrace
376
-
377
- ### Info
378
-
379
- The two classes Eitil::StackTrace::Stack and Eitil::StackTrace::Call, and the single module Eitil::StackTrace::Audit, provide the utility of easily viewing and storing the current stacktrace anywhere in your code. By initializing stack = Eitil::StackTrace::Stack.new, you can call methods as stack.report (returns the stacktrace as array), stack.show (pretty prints the stacktrace) and stack.find (accepts a block to find a call).
380
-
381
- You can also store the stacktrace of a record's update action into its audit. In order to do so, you need 1) to include Eitil::StackTrace::Audit into your model, and 2) add a :stacktrace column to your audits through the following migration.
382
-
383
- ### Migration
384
-
385
- ```ruby
386
- def change
387
- add_column :audits, :stacktrace, :text, array: true, default: []
388
- end
389
- ```
390
-
391
-
392
-
data/lib/eitil.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "eitil/version"
2
2
  require "eitil/engine"
3
+ require "eitil/railtie"
3
4
 
4
5
  module Eitil
5
- # Your code goes here...
6
6
  end
data/lib/eitil/all.rb ADDED
@@ -0,0 +1,15 @@
1
+
2
+ require "rails"
3
+ require "eitil"
4
+
5
+ Eitil::Layers.each do |layer|
6
+
7
+ begin
8
+ require "#{layer}/railtie"
9
+ puts "succesfully required #{layer}/railtie"
10
+
11
+ rescue LoadError
12
+ puts "failed to require #{layer}/railtie"
13
+
14
+ end
15
+ end
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
@@ -0,0 +1,6 @@
1
+ module Eitil
2
+
3
+ class Railtie < ::Rails::Railtie
4
+ end
5
+
6
+ end
data/lib/eitil/version.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  module Eitil
2
- VERSION = '0.3.10'
2
+
3
+ VERSION = '1.0.0'
4
+
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eitil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.10
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-09 00:00:00.000000000 Z
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: Description of Eitil.
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,41 +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
- - app/models/eitil/stack_trace/audit.rb
56
- - app/models/eitil/stack_trace/call.rb
57
- - app/models/eitil/stack_trace/stack.rb
58
- - config/initializers/modules/dir.rb
59
- - config/initializers/monkeys/application_controller.rb
60
- - config/initializers/monkeys/application_record.rb
61
- - config/initializers/monkeys/date_time.rb
62
- - config/initializers/monkeys/float.rb
63
- - config/initializers/monkeys/hash.rb
64
- - config/initializers/monkeys/kernel.rb
65
- - config/initializers/monkeys/module.rb
66
- - config/initializers/monkeys/object.rb
67
- - config/initializers/monkeys/string.rb
68
- - config/initializers/wrappers/decorators/application_decorator.rb
69
- - config/initializers/wrappers/decorators/controller_decorator.rb
70
- - config/initializers/wrappers/jobs/active_job_macros.rb
71
- - config/initializers/wrappers/jobs/single_method_job.rb
72
- - config/initializers/wrappers/routes/extended_resources.rb
73
- - config/initializers/wrappers/scopes/default_scopes.rb
74
- - config/routes.rb
75
55
  - lib/eitil.rb
56
+ - lib/eitil/all.rb
76
57
  - lib/eitil/engine.rb
58
+ - lib/eitil/railtie.rb
77
59
  - lib/eitil/version.rb
78
60
  - lib/tasks/eitil_tasks.rake
79
- homepage: https://eitje.app
61
+ homepage: https://github.com/eitje-app/eitil_engine
80
62
  licenses:
81
63
  - MIT
82
64
  metadata:
83
- homepage_uri: https://eitje.app
84
- source_code_uri: https://eitje.app
85
- changelog_uri: https://eitje.app
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
86
68
  post_install_message:
87
69
  rdoc_options: []
88
70
  require_paths:
@@ -101,5 +83,6 @@ requirements: []
101
83
  rubygems_version: 3.1.2
102
84
  signing_key:
103
85
  specification_version: 4
104
- summary: Summary of Eitil.
86
+ summary: Eitil (eitje utility) never stops increasing your life's efficacy and productivity,
87
+ yay!
105
88
  test_files: []
@@ -1,4 +0,0 @@
1
- module Eitil
2
- class ApplicationController < ActionController::API
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module Eitil
2
- class ApplicationJob < ActiveJob::Base
3
- end
4
- end
@@ -1,6 +0,0 @@
1
- module Eitil
2
- class ApplicationMailer < ActionMailer::Base
3
- default from: 'from@example.com'
4
- layout 'mailer'
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- module Eitil
2
- class ApplicationRecord < ActiveRecord::Base
3
- self.abstract_class = true
4
- end
5
- end
@@ -1,15 +0,0 @@
1
- module Eitil::StackTrace::Audit
2
- extend ActiveSupport::Concern
3
- included do
4
-
5
- private
6
-
7
- after_update :add_stacktrace_to_audit
8
-
9
- def add_stacktrace_to_audit
10
- stacktrace = Eitil::StackTrace::Stack.new.report
11
- self.audits.last.update(stacktrace: stacktrace)
12
- end
13
-
14
- end
15
- end
@@ -1,17 +0,0 @@
1
- module Eitil::StackTrace
2
- class Call
3
-
4
- attr_reader :program, :line, :meth
5
-
6
- CALL_RE = /(.*):(\d+):in `(.*)'/
7
-
8
- def initialize(string)
9
- @program, @line, @meth = CALL_RE.match(string).captures
10
- end
11
-
12
- def to_s
13
- "#{"#{meth}".ljust(50)} #{"(#{line})".ljust(6)} #{program}"
14
- end
15
-
16
- end
17
- end
@@ -1,28 +0,0 @@
1
- module Eitil::StackTrace
2
- class Stack
3
-
4
- attr_reader :stack, :backtrace
5
-
6
- def initialize
7
- @stack = caller[1..]
8
- @backtrace = stack.map { |call| Eitil::StackTrace::Call.new(call) }
9
- end
10
-
11
- def report
12
- backtrace.map(&:to_s)
13
- end
14
-
15
- def show
16
- ap report
17
- end
18
-
19
- def find(&block)
20
- backtrace.find(&block)
21
- end
22
-
23
- def self.parse(array_as_string)
24
- array_as_string.sub('[', ' ').reverse.sub(']','').reverse.split(',').flatten
25
- end
26
-
27
- end
28
- end
@@ -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,30 +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
- class << self
8
-
9
- def all_associations
10
- reflect_on_all_associations.map do |assoc|
11
- { assoc.name => assoc.association_class.to_s.demodulize }
12
- end.inject &:merge
13
- end
14
-
15
- def where_like(_hash)
16
- column, like = _hash.first
17
- where("LOWER(#{column}) LIKE ?", "%#{like.downcase}%")
18
- end
19
-
20
- def find_by_like(_hash)
21
- column, like = _hash.first
22
- find_by("LOWER(#{column}) LIKE ?", "%#{like.downcase}%")
23
- end
24
-
25
- end
26
-
27
- end
28
- end
29
-
30
- ApplicationRecord.send :include, ApplicationRecordMonkey
@@ -1,7 +0,0 @@
1
- class DateTime
2
-
3
- def prettify
4
- strftime "%Y-%m-%d.%H:%M:%S"
5
- end
6
-
7
- end
@@ -1,9 +0,0 @@
1
- class Float
2
-
3
- # converts a float to an integer, only when no decimal values are lost.
4
-
5
- def safe_to_i
6
- self == self.to_i ? self.to_i : self
7
- end
8
-
9
- end
@@ -1,14 +0,0 @@
1
- class Hash
2
-
3
- def auto_dig(_hash = self, _key)
4
- return _hash[_key] if _hash.fetch(_key, false)
5
-
6
- _hash.keys.each do |k|
7
- answer = auto_dig(_hash[k], _key) if _hash[k].is_a? Hash
8
- return answer if answer
9
- end
10
-
11
- nil
12
- end
13
-
14
- end
@@ -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,96 +0,0 @@
1
- class String
2
-
3
- # The NumberRegex belows comes from the Rubinius source code and
4
- # identifies both integers and floats correctly.
5
-
6
- NumberRegex = /^\s*[+-]?((\d+_?)*\d+(\.(\d+_?)*\d+)?|\.(\d+_?)*\d+)(\s*|([eE][+-]?(\d+_?)*\d+)\s*)$/
7
-
8
- def is_nan?
9
- self !~ NumberRegex
10
- end
11
-
12
- def is_num?
13
- !is_nan?
14
- end
15
-
16
- end
17
-
18
- # Descending classes which are always numeric
19
-
20
- class Numeric
21
-
22
- def is_nan?
23
- false
24
- end
25
-
26
- def is_num?
27
- true
28
- end
29
-
30
- end
31
-
32
- # Classes which are never numeric
33
-
34
- class NilClass
35
-
36
- def is_nan?
37
- true
38
- end
39
-
40
- def is_num?
41
- false
42
- end
43
-
44
- end
45
-
46
-
47
- class TrueClass
48
-
49
- def is_nan?
50
- true
51
- end
52
-
53
- def is_num?
54
- false
55
- end
56
-
57
- end
58
-
59
-
60
- class FalseClass
61
-
62
- def is_nan?
63
- true
64
- end
65
-
66
- def is_num?
67
- false
68
- end
69
-
70
- end
71
-
72
-
73
- class Hash
74
-
75
- def is_nan?
76
- true
77
- end
78
-
79
- def is_num?
80
- false
81
- end
82
-
83
- end
84
-
85
-
86
- class Array
87
-
88
- def is_nan?
89
- true
90
- end
91
-
92
- def is_num?
93
- false
94
- end
95
-
96
- 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
@@ -1,2 +0,0 @@
1
- Eitil::Engine.routes.draw do
2
- end