eitil 0.3.7 → 1.0.1.e.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24a0dccf0357bf5e01f41be73b6b1d4c840cbb8efa233ab772ad1c6c8bd94cff
4
- data.tar.gz: 7dc80a7a0268a68302fa74ddc1e0f371a83fba8a77dee2cb38a5ad03c08b3688
3
+ metadata.gz: 9e69ced77b66d59f27e9099a7797a456cde74b16c6335ef8b5a2ac97c66b5682
4
+ data.tar.gz: 46b8fe67b5ff1565a08c0e9305890f60af39706da8f7c32a63641ebef6273666
5
5
  SHA512:
6
- metadata.gz: 6d4a5e8baadfbd18962a5452e42b2051dff922765fbd2a53dcbe15a415a8e805a031efe18defc70d7360f52701d12b2ddcbbc07a96dc8ae2cffd3c33e121a636
7
- data.tar.gz: 83a19e9611e3553faf36663b5676c1abb3bc81af22052014cc250f8230665ce36b98a606a4a834923d2c24d81f7c347fa27ab91171a1cd74ca25a871e81d4e7a
6
+ metadata.gz: 24a0162b9243e07c02fe243a69f13ade1b2e94ecf27b6f23178439ade082078ca7c4fa6e2c651a5452fa56496b25eeed820b689e34cd244c29e78f6d95a1654a
7
+ data.tar.gz: f5ddd6a9820025ac558361761132d0da305f511d0b8f9edca3c2469aa49a1a98e09f63382a8463f293756556ac6a5fc9084ad6f155712211f348c2d52b0d60ae
data/README.md CHANGED
@@ -1,365 +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:
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:
11
+ ## Layers
29
12
 
30
- ```ruby
31
-
32
- gem 'eitil', path: "/Users/jurriaanschrofer/Documents/eitil"
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.
33
18
 
34
- ```
35
19
 
36
20
 
21
+ ## Cherry picking utilities
37
22
 
38
- # Monkey patches
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:
39
24
 
40
25
 
26
+ ### 1. include a single method
41
27
 
42
- ## Kernel
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.
43
29
 
44
30
  ```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
- ```
80
31
 
32
+ require "eitil_core/hash/auto_dig"
81
33
 
34
+ # This will simply add the patched Hash#auto_dig into your main application.
82
35
 
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
36
  ```
90
37
 
91
38
 
39
+ ### 2. include a collection of methods
92
40
 
93
- ## Module
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:
94
42
 
95
43
  ```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
- ```
103
44
 
45
+ require "eitil_core/hash"
104
46
 
47
+ # This will add all Hash patches into your project.
105
48
 
106
- ## Hash
107
-
108
- ```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
49
  ```
114
50
 
115
51
 
52
+ ### 3. include a whole layer
116
53
 
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
- ```
125
-
126
-
54
+ A whole layer, for example all utilities provided by EitilCore, can be included at once in your application.rb file:
127
55
 
128
- ## ApplicationRecord
129
56
 
130
57
  ```ruby
131
- self.all_associations
132
- # returns all associations for a given model
133
- # call as: Environment.all_associations
134
58
 
135
- self.where_like(_hash)
136
- # runs .where with your string field made into a wildcard and case insensitive
137
- # call as: User.where_like(name: 'jurriaan')
59
+ # config/application.rb
138
60
 
139
- self.find_by_like(_hash)
140
- # runs .find_by with your string field made into a wildcard and case insensitive
141
- # call as: User.find_by_like(name: 'jurriaan')
142
- ```
143
-
144
-
145
-
146
- ## DateTime
147
-
148
- ```ruby
149
- prettify
150
- # formats DateTime instances into a pretty, simple and filename friendly format
151
- # call as: DateTime.now.prettify
152
- # => "2021-04-21.17:51:42"
153
- ```
154
-
155
-
156
-
157
- # Wrappers
158
-
159
-
160
-
161
- ## Decorators
162
-
163
- ### Info
164
-
165
- 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.
166
-
167
- ### Decorate Macro
168
-
169
- ```ruby
170
- decorate(dec_item, dec_method: nil, dec_class: nil, **dec_kwargs)
171
- ```
172
-
173
- - dec_item is the instance that will be decorated
174
- - 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.
175
- - 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).
176
- - dec_kwargs enables you to provide additional arguments, which will be passed to your decorator method.
177
-
178
- ### Configuration
179
-
180
- 1. Your decorator classes should inherit from Eitil::ApplicationDecorator.
181
- 2. Your controllers should inherit the module Eitil::ControllerDecorator, through inclusion in a superclass.
182
- 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:
183
-
184
- ```ruby
185
- # initializers/eitil.rb
186
-
187
- Eitil.set_config do |config|
188
- 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
189
65
  end
66
+
190
67
  ```
191
68
 
192
69
 
193
70
 
194
- ## Router
195
-
196
- ### Info
197
-
198
- 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.
71
+ ### 4. include all alyers
199
72
 
200
- ### Create New Route Macro
73
+ Just like you can include a single eitil layer, you can also include them all at once:
201
74
 
202
- The first macro, new_route, enables you to create new route objects which may be called and used by different controllers.
203
75
 
204
76
  ```ruby
205
- # config/routes.rb
206
77
 
207
- new_route(verb, _method, action, scope)
208
- # call as: new_route :post, :attachment, "add_attachment", :member
209
- ```
210
-
211
- - verb refers to the http_verb, e.g. :put.
212
- - 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.
213
- - action refers to the controller action to which you want to redirect to request, e.g. :update_user.
214
- - scope refers to the url and can be set to either :member or :collection.
215
-
216
- ### Add Routes Macro
217
-
218
- 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.
219
-
220
- ```ruby
221
- # config/routes.rb
222
-
223
- extended_resources(controller, **kwargs)
224
- # call as: extended_resources :posts, only: [:create, :update, :attachment]
225
-
226
- ```
227
-
228
- ### Configuration
229
-
230
- The router wrapper is a single module which is automatically included into your application's router file, therefore no configuration is required.
231
-
232
-
233
-
234
- ## Jobs
235
-
236
- ### Info
237
-
238
- 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.
239
-
240
- ### Job Macro
241
-
242
- ```ruby
243
- new_job(_method, *args, **kwargs)
244
- # assuming a method :hello_world, call as: new_job :hello_world
245
- # => defines :hello_world_job
246
-
247
- new_job_debugger(_method, *args, **kwargs)
248
- # assuming a method :hello_world, call as: new_job_debugger :hello_world
249
- # => defines :hello_world_job_debugger
250
- ```
251
-
252
- - method is
253
-
254
- ### Configuration
255
-
256
- The new_job macro is monkey patched into Kernel, therefore no configuration is required.
257
-
258
-
259
-
260
- ## Scopes
78
+ # config/application.rb
261
79
 
262
- ### Info
263
-
264
- The Eitil scopes wrapper creates various default scopes for a model.
265
-
266
- ### The Scopes
267
-
268
- 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:
269
-
270
- ```ruby
271
- # columns of datatype: boolean
272
- .{column_name}_true
273
- .{column_name}_false
274
-
275
- # columns of datatype: datetime
276
- .{column_name}_today
277
- .{column_name}_past
278
- .{column_name}_future
279
- .{column_name}_on_date(date)
280
- .{column_name}_before_date(date)
281
- .{column_name}_after_date(date)
282
- .{column_name}_between_dates(start_date, end_date)
283
- .{column_name}_oldest_first
284
- .{column_name}_newest_first
285
-
286
- # columns of datatype: date
287
- .{column_name}_today
288
- .{column_name}_past
289
- .{column_name}_future
290
- .{column_name}_on_date(date)
291
- .{column_name}_before_date(date)
292
- .{column_name}_after_date(date)
293
- .{column_name}_between_dates(start_date, end_date)
294
- .{column_name}_oldest_first
295
- .{column_name}_newest_first
296
-
297
- # columns of datatype: integer
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
304
-
305
- # columns of datatype: float
306
- .{column_name}_equal_to(number)
307
- .{column_name}_lower_than(number)
308
- .{column_name}_higher_than(number)
309
- .{column_name}_between(min, max)
310
- .{column_name}_ascending
311
- .{column_name}_descending
80
+ module MyApplication
81
+ class Application < Rails::Application
82
+ require 'eitil/all'
83
+ end
84
+ end
85
+
312
86
  ```
313
87
 
314
- ### Configuration
315
-
316
- Your models should inherit the module Eitil::DefaultScopes through inclusion in a superclass, such as ApplicationRecord.
317
88
 
318
89
 
319
90
 
320
- # Modules & Classes
321
-
322
-
323
-
324
- ## Eitil::Dir
325
-
326
- ### Info
327
-
328
- The Eitil::Dir module provides methods which help you introspect your Rails project.
91
+ ## Installation
329
92
 
330
- ### Methods
93
+ Add eitil to your gemfile:
331
94
 
332
95
  ```ruby
333
- Eitil::Dir.contents(directory='app')
334
- # returns all files and subdirectories of a given directory
335
-
336
- Eitil::Dir.files(directory='app')
337
- # returns all files of a given directory
338
96
 
339
- Eitil::Dir.subdirs(directory='app')
340
- # returns all subdirectories of a given directory
97
+ gem 'eitil', '1.0.0' # check the latest version on https://rubygems.org/gems/eitil
341
98
 
342
- Eitil::Dir.lines(directory='app')
343
- # returns the total amount of lines of all files of a given directory
344
99
  ```
345
100
 
346
-
347
-
348
- ## Eitil::StackTrace
349
-
350
- ### Info
351
-
352
- 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).
353
-
354
- 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.
355
-
356
- ### Migration
357
-
358
- ```ruby
359
- def change
360
- add_column :audits, :stacktrace, :text, array: true, default: []
361
- end
362
- ```
363
-
364
-
365
-
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,18 @@
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 => e
12
+ puts "failed to require #{layer}/railtie"
13
+ puts "message: #{e.message}"
14
+ puts "backtrace: #{e.backtrace}"
15
+ binding.pry
16
+
17
+ end
18
+ 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.7'
2
+
3
+ VERSION = '1.0.1.e.1'
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.7
4
+ version: 1.0.1.e.1
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-07 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,39 +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/hash.rb
63
- - config/initializers/monkeys/kernel.rb
64
- - config/initializers/monkeys/module.rb
65
- - config/initializers/monkeys/object.rb
66
- - config/initializers/wrappers/decorators/application_decorator.rb
67
- - config/initializers/wrappers/decorators/controller_decorator.rb
68
- - config/initializers/wrappers/jobs/active_job_macros.rb
69
- - config/initializers/wrappers/jobs/single_method_job.rb
70
- - config/initializers/wrappers/routes/extended_resources.rb
71
- - config/initializers/wrappers/scopes/default_scopes.rb
72
- - config/routes.rb
73
55
  - lib/eitil.rb
56
+ - lib/eitil/all.rb
74
57
  - lib/eitil/engine.rb
58
+ - lib/eitil/railtie.rb
75
59
  - lib/eitil/version.rb
76
60
  - lib/tasks/eitil_tasks.rake
77
- homepage: https://eitje.app
61
+ homepage: https://github.com/eitje-app/eitil_engine
78
62
  licenses:
79
63
  - MIT
80
64
  metadata:
81
- homepage_uri: https://eitje.app
82
- source_code_uri: https://eitje.app
83
- 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
84
68
  post_install_message:
85
69
  rdoc_options: []
86
70
  require_paths:
@@ -92,12 +76,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
76
  version: '0'
93
77
  required_rubygems_version: !ruby/object:Gem::Requirement
94
78
  requirements:
95
- - - ">="
79
+ - - ">"
96
80
  - !ruby/object:Gem::Version
97
- version: '0'
81
+ version: 1.3.1
98
82
  requirements: []
99
83
  rubygems_version: 3.1.2
100
84
  signing_key:
101
85
  specification_version: 4
102
- summary: Summary of Eitil.
86
+ summary: Eitil (eitje utility) never stops increasing your life's efficacy and productivity,
87
+ yay!
103
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,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,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