eitil 0.3.10 → 1.0.1.e.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -331
  3. data/eitil_core/README.md +288 -0
  4. data/eitil_core/lib/eitil_core.rb +24 -0
  5. data/eitil_core/lib/eitil_core/application_controller.rb +2 -0
  6. data/eitil_core/lib/eitil_core/application_controller/slice_params.rb +14 -0
  7. data/eitil_core/lib/eitil_core/application_record.rb +4 -0
  8. data/eitil_core/lib/eitil_core/application_record/all_associations.rb +16 -0
  9. data/eitil_core/lib/eitil_core/application_record/find_by_like.rb +15 -0
  10. data/eitil_core/lib/eitil_core/application_record/where_like.rb +15 -0
  11. data/eitil_core/lib/eitil_core/argument_helpers.rb +5 -0
  12. data/eitil_core/lib/eitil_core/argument_helpers/all_args_to_ivars.rb +12 -0
  13. data/eitil_core/lib/eitil_core/argument_helpers/all_kwargs_to_ivars.rb +12 -0
  14. data/eitil_core/lib/eitil_core/argument_helpers/args_to_ivars.rb +12 -0
  15. data/eitil_core/lib/eitil_core/concerns.rb +2 -0
  16. data/{config/initializers/monkeys/module.rb → eitil_core/lib/eitil_core/concerns/include_concerns_of.rb} +3 -0
  17. data/eitil_core/lib/eitil_core/datetime.rb +2 -0
  18. data/{config/initializers/monkeys/date_time.rb → eitil_core/lib/eitil_core/datetime/prettify.rb} +3 -0
  19. data/eitil_core/lib/eitil_core/errors.rb +2 -0
  20. data/eitil_core/lib/eitil_core/errors/raise_error.rb +11 -0
  21. data/eitil_core/lib/eitil_core/float.rb +2 -0
  22. data/{config/initializers/monkeys/float.rb → eitil_core/lib/eitil_core/float/safe_to_i.rb} +0 -0
  23. data/eitil_core/lib/eitil_core/hash.rb +2 -0
  24. data/{config/initializers/monkeys/hash.rb → eitil_core/lib/eitil_core/hash/auto_dig.rb} +3 -0
  25. data/eitil_core/lib/eitil_core/lookups.rb +2 -0
  26. data/{config/initializers/monkeys/object.rb → eitil_core/lib/eitil_core/lookups/all_methods.rb} +3 -0
  27. data/eitil_core/lib/eitil_core/railtie.rb +37 -0
  28. data/eitil_core/lib/eitil_core/safe_executions.rb +3 -0
  29. data/eitil_core/lib/eitil_core/safe_executions/safe_call.rb +12 -0
  30. data/eitil_core/lib/eitil_core/safe_executions/safe_send.rb +12 -0
  31. data/eitil_core/lib/eitil_core/setters.rb +2 -0
  32. data/eitil_core/lib/eitil_core/setters/set_ivars.rb +12 -0
  33. data/eitil_core/lib/eitil_core/type_checkers.rb +2 -0
  34. data/{config/initializers/monkeys/string.rb → eitil_core/lib/eitil_core/type_checkers/is_num_or_nan.rb} +5 -5
  35. data/eitil_core/lib/eitil_core/validations.rb +2 -0
  36. data/eitil_core/lib/eitil_core/validations/run_validations.rb +10 -0
  37. data/eitil_integrate/README.md +8 -0
  38. data/eitil_integrate/lib/eitil_integrate.rb +0 -0
  39. data/eitil_integrate/lib/eitil_integrate/railtie.rb +10 -0
  40. data/eitil_store/README.md +16 -0
  41. data/eitil_store/lib/eitil_store.rb +4 -0
  42. data/eitil_store/lib/eitil_store/railtie.rb +10 -0
  43. data/eitil_store/lib/eitil_store/regex.rb +4 -0
  44. data/eitil_store/lib/eitil_store/regex/regex.rb +41 -0
  45. data/eitil_support/README.md +78 -0
  46. data/eitil_support/lib/eitil_support.rb +5 -0
  47. data/eitil_support/lib/eitil_support/directory.rb +2 -0
  48. data/eitil_support/lib/eitil_support/directory/lookups.rb +23 -0
  49. data/eitil_support/lib/eitil_support/railtie.rb +10 -0
  50. data/eitil_support/lib/eitil_support/stacktrace.rb +4 -0
  51. data/{app/models/eitil/stack_trace → eitil_support/lib/eitil_support/stacktrace}/audit.rb +2 -2
  52. data/{app/models/eitil/stack_trace → eitil_support/lib/eitil_support/stacktrace}/call.rb +1 -1
  53. data/{app/models/eitil/stack_trace → eitil_support/lib/eitil_support/stacktrace}/stack.rb +2 -2
  54. data/eitil_wrapper/README.md +181 -0
  55. data/eitil_wrapper/lib/eitil_wrapper.rb +7 -0
  56. data/eitil_wrapper/lib/eitil_wrapper/decorators.rb +3 -0
  57. data/{config/initializers/wrappers → eitil_wrapper/lib/eitil_wrapper}/decorators/application_decorator.rb +1 -1
  58. data/eitil_wrapper/lib/eitil_wrapper/decorators/controller_decorator.rb +60 -0
  59. data/eitil_wrapper/lib/eitil_wrapper/jobs.rb +4 -0
  60. data/eitil_wrapper/lib/eitil_wrapper/jobs/new_job.rb +34 -0
  61. data/eitil_wrapper/lib/eitil_wrapper/jobs/new_job_debugger.rb +37 -0
  62. data/eitil_wrapper/lib/eitil_wrapper/jobs/single_method_job.rb +8 -0
  63. data/eitil_wrapper/lib/eitil_wrapper/railtie.rb +49 -0
  64. data/eitil_wrapper/lib/eitil_wrapper/routes.rb +2 -0
  65. data/{config/initializers/wrappers → eitil_wrapper/lib/eitil_wrapper}/routes/extended_resources.rb +2 -2
  66. data/eitil_wrapper/lib/eitil_wrapper/scopes.rb +2 -0
  67. data/eitil_wrapper/lib/eitil_wrapper/scopes/default_scopes.rb +80 -0
  68. data/lib/eitil.rb +1 -1
  69. data/lib/eitil/all.rb +18 -0
  70. data/lib/eitil/engine.rb +24 -0
  71. data/lib/eitil/railtie.rb +6 -0
  72. data/lib/eitil/version.rb +3 -1
  73. metadata +82 -34
  74. data/app/controllers/eitil/application_controller.rb +0 -4
  75. data/app/jobs/eitil/application_job.rb +0 -4
  76. data/app/mailers/eitil/application_mailer.rb +0 -6
  77. data/app/models/eitil/application_record.rb +0 -5
  78. data/config/initializers/modules/dir.rb +0 -21
  79. data/config/initializers/monkeys/application_controller.rb +0 -14
  80. data/config/initializers/monkeys/application_record.rb +0 -30
  81. data/config/initializers/monkeys/kernel.rb +0 -48
  82. data/config/initializers/wrappers/decorators/controller_decorator.rb +0 -63
  83. data/config/initializers/wrappers/jobs/active_job_macros.rb +0 -52
  84. data/config/initializers/wrappers/jobs/single_method_job.rb +0 -24
  85. data/config/initializers/wrappers/scopes/default_scopes.rb +0 -83
  86. 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: 5232de873f2bceae1b35b083d012bfce49232bc8ca31f44dd8ca59813817dfb9
4
+ data.tar.gz: 1db3364578e717a1cf277f5716d22b9d2e4d13a993bd814861cc4a2ad6a3adc5
5
5
  SHA512:
6
- metadata.gz: 706798e2c7e5e1f81cd413a5698fa030eedcc606dae5a2a6ade7fd74bc21cfa1e485cc3a7c782097aa7cac2271d879f91e8d0791627540df9acd03e8bc873273
7
- data.tar.gz: c33996734e261cc3419ad9dfcec4dd271ecb40be39cc0dac2ae44156f750329a179a3988ba0a4d574a27fa8d411b1542f230c566544d9bb67ef4f6c60d93dc1a
6
+ metadata.gz: b3cae8cfdd62e6dfa886bc74dd3df3c360eaed551a372969caa5fb0667e56b80ba00a41c8916fe4ab3edbc1467a83a00157f0bf02490e93f00b0f8a81dd5d420
7
+ data.tar.gz: fbff1d6ed87e89fcb9082e8b04d5cc980d7e152817f3fb590f710abb536b5ad7125f08809df106debfe964f15ea89a515669705fe37327450a9c8493300c435f
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
-
@@ -0,0 +1,288 @@
1
+
2
+
3
+
4
+ # EitilCore
5
+
6
+ EitilCore extends the core classes of Ruby and Rails.
7
+
8
+
9
+ ## ApplicationController
10
+
11
+ ```ruby
12
+
13
+ require "eitil_core/application_controller"
14
+
15
+ ```
16
+
17
+ ```ruby
18
+ # require "eitil_core/application_controller/slice_params"
19
+
20
+ slice_params(*args)
21
+ # slices request params, converts them to JSON and symbolizes the keys
22
+ # call as: slice_params :id, :user
23
+ # => { id: 1, user: 69 }
24
+ ```
25
+
26
+
27
+ ## ApplicationRecord
28
+
29
+ ```ruby
30
+
31
+ require "eitil_core/application_controller"
32
+
33
+ ```
34
+
35
+ ```ruby
36
+ # require "eitil_core/application_record/find_by_like"
37
+
38
+ self.find_by_like(_hash)
39
+ # runs .find_by with your string field made into a wildcard and case insensitive
40
+ # call as: User.find_by_like(name: 'jurriaan')
41
+ ```
42
+
43
+ ```ruby
44
+ # require "eitil_core/application_record/where_like"
45
+
46
+ self.where_like(_hash)
47
+ # runs .where with your string field made into a wildcard and case insensitive
48
+ # call as: User.where_like(name: 'jurriaan')
49
+ ```
50
+
51
+ ```ruby
52
+ # require "eitil_core/application_record/all_associations"
53
+
54
+ self.all_associations
55
+ # returns all associations for a given model
56
+ # call as: Environment.all_associations
57
+ ```
58
+
59
+
60
+ ## ArgumentHelpers
61
+
62
+ ```ruby
63
+
64
+ require "eitil_core/arugment_helpers"
65
+
66
+ ```
67
+
68
+
69
+ ```ruby
70
+ # require "eitil_core/argument_helpers/all_args_to_ivars"
71
+
72
+ all_args_to_ivars(binding)
73
+ # sets all keywords arguments of the method's local binding to instance variables
74
+ # call as: all_args_to_ivars binding
75
+ ```
76
+
77
+
78
+ ```ruby
79
+ # require "eitil_core/argument_helpers/args_to_ivars"
80
+
81
+ args_to_ivars(binding, *local_vars)
82
+ # sets specified keywords arguments of the method's local binding to instance variables
83
+ # call as: all_args_to_ivars binding :user_id, :user_name
84
+ ```
85
+
86
+
87
+ ```ruby
88
+ # require "eitil_core/argument_helpers/all_kwargs_to_ivars"
89
+
90
+ all_kwargs_to_ivars(local_binding, namespace= :kwargs)
91
+ # sets the method's **kwargs argument to instance variables, with each key as the ivar's "@#{name}" and the value as its value
92
+ # call as: kwargs_to_ivars binding
93
+ # the keywords container name can be overwritten, e.g. the common :attributes
94
+ ```
95
+
96
+
97
+ ## Concerns
98
+
99
+ ```ruby
100
+
101
+ require "eitil_core/concerns"
102
+
103
+ ```
104
+
105
+ ```ruby
106
+ # require "eitil_core/concerns/include_concerns_of"
107
+
108
+ include_concerns_of(*directories, namespace: nil)
109
+ # includes models/concerns/{directories}/* if no namespace if given, or all concerns within the given namespace
110
+ # call as: include_concerns_of :user, :mail
111
+ # => includes all modules of models/concerns/user/* and models/oncerns/mail/*
112
+ # or call as: include_concerns_of :request_service, namespace: Eivid::Concerns
113
+ # tip: call Class.included_modules to view all included modules
114
+ ```
115
+
116
+
117
+ ## DateTime
118
+
119
+ ```ruby
120
+
121
+ require "eitil_core/datetime"
122
+
123
+ ```
124
+
125
+ ```ruby
126
+ # require "eitil_core/datetime/prettify"
127
+
128
+ prettify
129
+ # formats DateTime instances into a pretty, simple and filename friendly format
130
+ # call as: DateTime.now.prettify
131
+ # => "2021-04-21.17:51:42"
132
+ ```
133
+
134
+
135
+ ## Errors
136
+
137
+ ```ruby
138
+
139
+ require "eitil_core/errors"
140
+
141
+ ```
142
+
143
+ ```ruby
144
+ # require "eitil_core/errors/raise_error"
145
+
146
+ raise_error(_class_name, message = nil)
147
+ # creates an error class if currently undefined, inheriting from StandardError, and raises the error with the given message
148
+ # call as: raise_error "SomethingWentWrongError", "check your code, bro!"
149
+ # => SomethingWentWrongError (check your code, bro!)
150
+ ```
151
+
152
+
153
+ ## Float
154
+
155
+ ```ruby
156
+
157
+ require "eitil_core/float"
158
+
159
+ ```
160
+
161
+ ```ruby
162
+ # require "eitil_core/float/safe_to_i"
163
+
164
+ safe_to_i
165
+ # converts a float to an integer, only when no decimal values are lost.
166
+ # 8.00.safe_to_i returns 8 (Integer)
167
+ # 8.88.safe_to_i returns 8.88 (Float)
168
+ ```
169
+
170
+
171
+ ## Hash
172
+
173
+ ```ruby
174
+
175
+ require "eitil_core/hash"
176
+
177
+ ```
178
+
179
+ ```ruby
180
+ # require "eitil_core/hash/auto_dig"
181
+
182
+ auto_dig(_hash = self, _key)
183
+ # finds the value for the given hash key, irregardless of the amount of nested layers
184
+ # call as: {a: 1, b: {c: 2, d: {e: 3}}}.auto_dig :e
185
+ # => 3
186
+ ```
187
+
188
+
189
+ ## Lookups
190
+
191
+ ```ruby
192
+
193
+ require "eitil_core/lookups"
194
+
195
+ ```
196
+
197
+ ```ruby
198
+ # require "eitil_core/lookups/all_methods"
199
+
200
+ all_methods(include_ancestors = true, grep: nil)
201
+ # pretty prints all methods for any object, grouped per type (e.g. private_methods, public_instance_methods)
202
+ # call as: Class.all_methods false, grep: /json/
203
+ ```
204
+
205
+
206
+ ## SafeExecutions
207
+
208
+ ```ruby
209
+
210
+ require "eitil_core/safe_executions"
211
+
212
+ ```
213
+
214
+ ```ruby
215
+ # require "eitil_core/safe_executions/safe_send"
216
+
217
+ safe_send(method, *args, return_value: nil)
218
+ # a safe version of .send, which in case of an error rescues and returns return_value (default: nil) instead
219
+ ```
220
+
221
+ ```ruby
222
+ # require "eitil_core/safe_executions/safe_call"
223
+
224
+ safe_call(*args, return_value: nil, &block)
225
+ # a safe version of .call, which in case of an error rescues and returns return_value (default: nil) instead
226
+ # accepts either a proc argument or a block
227
+ ```
228
+
229
+
230
+ ## Setters
231
+
232
+ ```ruby
233
+
234
+ require "eitil_core/setters"
235
+
236
+ ```
237
+
238
+ ```ruby
239
+ # require "eitil_core/setters/set_ivars"
240
+
241
+ set_ivars(*ivars)
242
+ # sets instance variables named @"#{ivar}" for each symbol passed, by invoking send("set_#{ivar}")
243
+ # e.g. set_ivars(:user) sets @user with the value returned by your local method .set_user
244
+ # call as: set_ivars :user, :authentication, :connection
245
+ ```
246
+
247
+
248
+ ## TypeCheckers
249
+
250
+ ```ruby
251
+
252
+ require "eitil_core/type_checkers"
253
+
254
+ ```
255
+
256
+ ```ruby
257
+ # require "eitil_core/type_checkers/is_num_or_nan"
258
+
259
+ is_num?
260
+ # returns true if a string matches the Rubinius source code regex for strings and integers, false otherwise
261
+ # comes in handy since ruby plays it safe on string to number conversion ('aaa'.to_f returns 0.0, thus is valid)
262
+ # this method is also implemented for all other classes, such as Integer, Float, NilClass, TrueClass, Hash and so on...
263
+
264
+ is_nan?
265
+ # returns true if a string does NOT match the Rubinius source code regex for strings and integers, false otherwise
266
+ # comes in handy since ruby plays it safe on string to number conversion ('aaa'.to_f returns 0.0, thus is valid)
267
+ # this method is also implemented for all other classes, such as Integer, Float, NilClass, TrueClass, Hash and so on...
268
+ ```
269
+
270
+
271
+ ## Validations
272
+
273
+ ```ruby
274
+
275
+ require "eitil_core/validations"
276
+
277
+ ```
278
+
279
+ ```ruby
280
+ # require "eitil_core/validations/run_validations"
281
+
282
+ run_validations(*validations)
283
+ # calls a method for each argument, namespaced as "validate_#{argument}"
284
+ # call as: run_validations(:single_receipt, :single_order)
285
+ # => calls #validate_single_receipt and #validate_single_order
286
+ ```
287
+
288
+