eitil 1.0.1.e.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/eitil_core/README.md +288 -0
  3. data/eitil_core/lib/eitil_core.rb +24 -0
  4. data/eitil_core/lib/eitil_core/application_controller.rb +2 -0
  5. data/eitil_core/lib/eitil_core/application_controller/slice_params.rb +14 -0
  6. data/eitil_core/lib/eitil_core/application_record.rb +4 -0
  7. data/eitil_core/lib/eitil_core/application_record/all_associations.rb +16 -0
  8. data/eitil_core/lib/eitil_core/application_record/find_by_like.rb +15 -0
  9. data/eitil_core/lib/eitil_core/application_record/where_like.rb +15 -0
  10. data/eitil_core/lib/eitil_core/argument_helpers.rb +5 -0
  11. data/eitil_core/lib/eitil_core/argument_helpers/all_args_to_ivars.rb +12 -0
  12. data/eitil_core/lib/eitil_core/argument_helpers/all_kwargs_to_ivars.rb +12 -0
  13. data/eitil_core/lib/eitil_core/argument_helpers/args_to_ivars.rb +12 -0
  14. data/eitil_core/lib/eitil_core/concerns.rb +2 -0
  15. data/eitil_core/lib/eitil_core/concerns/include_concerns_of.rb +15 -0
  16. data/eitil_core/lib/eitil_core/datetime.rb +2 -0
  17. data/eitil_core/lib/eitil_core/datetime/prettify.rb +10 -0
  18. data/eitil_core/lib/eitil_core/errors.rb +2 -0
  19. data/eitil_core/lib/eitil_core/errors/raise_error.rb +11 -0
  20. data/eitil_core/lib/eitil_core/float.rb +2 -0
  21. data/eitil_core/lib/eitil_core/float/safe_to_i.rb +9 -0
  22. data/eitil_core/lib/eitil_core/hash.rb +2 -0
  23. data/eitil_core/lib/eitil_core/hash/auto_dig.rb +17 -0
  24. data/eitil_core/lib/eitil_core/lookups.rb +2 -0
  25. data/eitil_core/lib/eitil_core/lookups/all_methods.rb +32 -0
  26. data/eitil_core/lib/eitil_core/railtie.rb +37 -0
  27. data/eitil_core/lib/eitil_core/safe_executions.rb +3 -0
  28. data/eitil_core/lib/eitil_core/safe_executions/safe_call.rb +12 -0
  29. data/eitil_core/lib/eitil_core/safe_executions/safe_send.rb +12 -0
  30. data/eitil_core/lib/eitil_core/setters.rb +2 -0
  31. data/eitil_core/lib/eitil_core/setters/set_ivars.rb +12 -0
  32. data/eitil_core/lib/eitil_core/type_checkers.rb +2 -0
  33. data/eitil_core/lib/eitil_core/type_checkers/is_num_or_nan.rb +96 -0
  34. data/eitil_core/lib/eitil_core/validations.rb +2 -0
  35. data/eitil_core/lib/eitil_core/validations/run_validations.rb +10 -0
  36. data/eitil_integrate/README.md +8 -0
  37. data/eitil_integrate/lib/eitil_integrate.rb +0 -0
  38. data/eitil_integrate/lib/eitil_integrate/railtie.rb +10 -0
  39. data/eitil_store/README.md +16 -0
  40. data/eitil_store/lib/eitil_store.rb +4 -0
  41. data/eitil_store/lib/eitil_store/railtie.rb +10 -0
  42. data/eitil_store/lib/eitil_store/regex.rb +4 -0
  43. data/eitil_store/lib/eitil_store/regex/regex.rb +41 -0
  44. data/eitil_support/README.md +78 -0
  45. data/eitil_support/lib/eitil_support.rb +5 -0
  46. data/eitil_support/lib/eitil_support/directory.rb +2 -0
  47. data/eitil_support/lib/eitil_support/directory/lookups.rb +23 -0
  48. data/eitil_support/lib/eitil_support/railtie.rb +10 -0
  49. data/eitil_support/lib/eitil_support/stacktrace.rb +4 -0
  50. data/eitil_support/lib/eitil_support/stacktrace/audit.rb +15 -0
  51. data/eitil_support/lib/eitil_support/stacktrace/call.rb +17 -0
  52. data/eitil_support/lib/eitil_support/stacktrace/stack.rb +28 -0
  53. data/eitil_wrapper/README.md +181 -0
  54. data/eitil_wrapper/lib/eitil_wrapper.rb +7 -0
  55. data/eitil_wrapper/lib/eitil_wrapper/decorators.rb +3 -0
  56. data/eitil_wrapper/lib/eitil_wrapper/decorators/application_decorator.rb +19 -0
  57. data/eitil_wrapper/lib/eitil_wrapper/decorators/controller_decorator.rb +60 -0
  58. data/eitil_wrapper/lib/eitil_wrapper/jobs.rb +4 -0
  59. data/eitil_wrapper/lib/eitil_wrapper/jobs/new_job.rb +34 -0
  60. data/eitil_wrapper/lib/eitil_wrapper/jobs/new_job_debugger.rb +37 -0
  61. data/eitil_wrapper/lib/eitil_wrapper/jobs/single_method_job.rb +8 -0
  62. data/eitil_wrapper/lib/eitil_wrapper/railtie.rb +49 -0
  63. data/eitil_wrapper/lib/eitil_wrapper/routes.rb +2 -0
  64. data/eitil_wrapper/lib/eitil_wrapper/routes/extended_resources.rb +40 -0
  65. data/eitil_wrapper/lib/eitil_wrapper/scopes.rb +2 -0
  66. data/eitil_wrapper/lib/eitil_wrapper/scopes/default_scopes.rb +80 -0
  67. data/lib/eitil/version.rb +1 -1
  68. metadata +69 -4
@@ -0,0 +1,4 @@
1
+
2
+ require "eitil_wrapper/jobs/new_job"
3
+ require "eitil_wrapper/jobs/new_job_debugger"
4
+ require "eitil_wrapper/jobs/single_method_job"
@@ -0,0 +1,34 @@
1
+
2
+ # require "eitil_wrapper/jobs/new_job"
3
+
4
+ require "eitil_wrapper/jobs/single_method_job"
5
+
6
+ Kernel.module_eval do
7
+
8
+ # BEWARE: _self is currently not accepted in perform_later jobs due to serialization errors
9
+
10
+ # The cases of 'id' and '_self' both handle instances, with the difference
11
+ # being that 'id' works for objects that have a database record, while '_self'
12
+ # works for non database supported instanes, such as an Exporter instance.
13
+
14
+ def new_job(_method, *args, **kwargs)
15
+
16
+ if instance_methods(false).include? _method
17
+ define_method "#{_method}_job" do |_self = nil, *args, **kwargs|
18
+
19
+ EitilWrapper::SingleMethodJob.perform_later(
20
+ *args, _class: self.class.to_s, _method: _method.to_s, id: safe_send(:id), _self: self.to_json, **kwargs
21
+ )
22
+ end
23
+
24
+ elsif singleton_methods(false).include? _method
25
+ define_singleton_method "#{_method}_job" do |*args, **kwargs|
26
+
27
+ EitilWrapper::SingleMethodJob.perform_later(
28
+ *args, _class: to_s, _method: _method.to_s, **kwargs
29
+ )
30
+ end
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,37 @@
1
+
2
+ # require "eitil_wrapper/jobs/new_job_debugger"
3
+
4
+ require "eitil_wrapper/jobs/single_method_job"
5
+
6
+ # BEWARE: This is an exact copy of the .new_job method, except for .perform_now instead of .perform_later and the method's name.
7
+ # The reason for not using helper methods is to not unnecessarily fill and potentially fuck up the Kernel environment.
8
+
9
+ Kernel.module_eval do
10
+
11
+ # BEWARE: _self is currently not accepted in perform_later jobs due to serialization errors
12
+
13
+ # The cases of 'id' and '_self' both handle instances, with the difference
14
+ # being that 'id' works for objects that have a database record, while '_self'
15
+ # works for non database supported instanes, such as an Exporter instance.
16
+
17
+ def new_job_debugger(_method, *args, **kwargs)
18
+
19
+ if instance_methods(false).include? _method
20
+ define_method "#{_method}_job_debugger" do |_self = nil, *args, **kwargs|
21
+
22
+ EitilWrapper::SingleMethodJob.perform_now(
23
+ *args, _class: self.class.to_s, _method: _method.to_s, id: safe_send(:id), _self: self.to_json, **kwargs
24
+ )
25
+ end
26
+
27
+ elsif singleton_methods(false).include? _method
28
+ define_singleton_method "#{_method}_job_debugger" do |*args, **kwargs|
29
+
30
+ EitilWrapper::SingleMethodJob.perform_now(
31
+ *args, _class: to_s, _method: _method.to_s, **kwargs
32
+ )
33
+ end
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,8 @@
1
+ # ISSUE: this code is currently defined eitil_wrapper/railtie.rb, since module inclusion
2
+ # somehow leads to errors in the initialization process. Ideally, this code would be
3
+ # defined in eitil_wrapper/jobs/single_method_job.rb and dispatched in eitil_wrapper/railtie.rb
4
+
5
+ module EitilWrapper
6
+ module CreateSingleMethodJob
7
+ end
8
+ end
@@ -0,0 +1,49 @@
1
+
2
+ require "rails"
3
+ require "eitil_wrapper"
4
+
5
+ module EitilWrapper
6
+
7
+ class Railtie < Rails::Railtie
8
+
9
+ initializer "my_railtie.configure_rails_initialization", options: :after do |app|
10
+
11
+ # Dynamic dispatching after initialization of Rails classes.
12
+
13
+ # Scopes
14
+
15
+ if Object.const_defined?('EitilWrapper::Scopes::DefaultScopes')
16
+ ::ApplicationRecord.send(:extend, EitilWrapper::Scopes::DefaultScopes)
17
+ end
18
+
19
+ # Jobs
20
+
21
+ if Object.const_defined?('EitilWrapper::CreateSingleMethodJob')
22
+
23
+ # ISSUE: this code is currently defined eitil_wrapper/railtie.rb, since module inclusion
24
+ # somehow leads to errors in the initialization process. Ideally, this code would be
25
+ # defined in eitil_wrapper/jobs/single_method_job.rb and dispatched in eitil_wrapper/railtie.rb
26
+
27
+ # BEWARE: _self is currently not accepted in perform_later jobs due to serialization errors
28
+
29
+ # BEWARE: The cases of 'id' and '_self' both handle instances, with the difference
30
+ # being that 'id' works for objects that have a database record, while '_self'
31
+ # works for non database supported instanes, such as an Exporter instance.
32
+
33
+ module ::EitilWrapper
34
+ class SingleMethodJob < ::ApplicationJob
35
+ def perform(*args, _class:, _method:, id: nil, _self: nil, **kwargs)
36
+ object =
37
+ if id
38
+ _class.constantize.find(id)
39
+ elsif _self
40
+ _self
41
+ else
42
+ _class.constantize
43
+ end
44
+ object.send _method, *args, **kwargs
45
+ end; end; end; end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,2 @@
1
+
2
+ require "eitil_wrapper/routes/extended_resources"
@@ -0,0 +1,40 @@
1
+ module EitilWrapper
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, EitilWrapper::ExtendedResources
@@ -0,0 +1,2 @@
1
+
2
+ require "eitil_wrapper/scopes/default_scopes"
@@ -0,0 +1,80 @@
1
+ module EitilWrapper
2
+ module Scopes
3
+ module DefaultScopes
4
+
5
+ SharableDateScopes = -> (_class, column) {
6
+ _class.eitil_scope :"#{column}_today", -> { where("#{column} = ?", Date.today) }
7
+ _class.eitil_scope :"#{column}_past", -> { where("#{column} < ?", Date.today) }
8
+ _class.eitil_scope :"#{column}_future", -> { where("#{column} > ?", Date.today) }
9
+
10
+ _class.eitil_scope :"#{column}_on_date", -> (date) { where("#{column} = ?", date) }
11
+ _class.eitil_scope :"#{column}_before_date", -> (date) { where("#{column} = ?", date) }
12
+ _class.eitil_scope :"#{column}_after_date", -> (date) { where("#{column} = ?", date) }
13
+ _class.eitil_scope :"#{column}_between_dates", -> (from, till) { where("#{column} >= ? and #{column} <= ?", from, till) }
14
+
15
+ _class.eitil_scope :"#{column}_oldest_first", -> { order("#{column} ASC") }
16
+ _class.eitil_scope :"#{column}_newest_first", -> { order("#{column} DESC") }
17
+ }
18
+
19
+ SharableNumScopes = -> (_class, column) {
20
+ _class.eitil_scope :"#{column}_equal_to", -> (number) { where("#{column} = ?", number) }
21
+ _class.eitil_scope :"#{column}_lower_than", -> (number) { where("#{column} = <", number) }
22
+ _class.eitil_scope :"#{column}_higher_than", -> (number) { where("#{column} = >", number) }
23
+ _class.eitil_scope :"#{column}_between", -> (min, max) { where("#{column} >= ? and #{column} <= ?", min, max) }
24
+
25
+ _class.eitil_scope :"#{column}_ascending", -> { order("#{column} ASC") }
26
+ _class.eitil_scope :"#{column}_descending", -> { order("#{column} DESC") }
27
+ }
28
+
29
+ def inherited(subclass)
30
+ super
31
+ subclass.use_eitil_scopes
32
+ end
33
+
34
+ def use_eitil_scopes
35
+ return if abstract_class?
36
+ %i[boolean datetime date integer float].each { |_type| send :"create_eitil_#{_type}_scopes" }
37
+ end
38
+
39
+ def eitil_scope(_name, _proc)
40
+ scope _name, _proc unless respond_to? _name
41
+ end
42
+
43
+ def columns_of_type(data_type)
44
+ columns_hash.select { |column,v| v.sql_type_metadata.type == data_type }
45
+ end
46
+
47
+ def create_eitil_boolean_scopes
48
+ columns_of_type(:boolean)&.map do |column, object|
49
+ eitil_scope :"#{column}_true", -> { where(column => true) }
50
+ eitil_scope :"#{column}_false", -> { where(column => [false, nil]) }
51
+ end
52
+ end
53
+
54
+ def create_eitil_datetime_scopes
55
+ columns_of_type(:datetime)&.map do |column, object|
56
+ SharableDateScopes.call self, column
57
+ end
58
+ end
59
+
60
+ def create_eitil_date_scopes
61
+ columns_of_type(:date)&.map do |column, object|
62
+ SharableDateScopes.call self, column
63
+ end
64
+ end
65
+
66
+ def create_eitil_integer_scopes
67
+ columns_of_type(:integer)&.map do |column, object|
68
+ SharableNumScopes.call self, column
69
+ end
70
+ end
71
+
72
+ def create_eitil_float_scopes
73
+ columns_of_type(:float)&.map do |column, object|
74
+ SharableNumScopes.call self, column
75
+ end
76
+ end
77
+
78
+ end
79
+ end
80
+ end
data/lib/eitil/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Eitil
2
2
 
3
- VERSION = '1.0.1.e.1'
3
+ VERSION = '1.0.2'
4
4
 
5
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: 1.0.1.e.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Schrofer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-11 00:00:00.000000000 Z
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,6 +52,71 @@ files:
52
52
  - MIT-LICENSE
53
53
  - README.md
54
54
  - Rakefile
55
+ - eitil_core/README.md
56
+ - eitil_core/lib/eitil_core.rb
57
+ - eitil_core/lib/eitil_core/application_controller.rb
58
+ - eitil_core/lib/eitil_core/application_controller/slice_params.rb
59
+ - eitil_core/lib/eitil_core/application_record.rb
60
+ - eitil_core/lib/eitil_core/application_record/all_associations.rb
61
+ - eitil_core/lib/eitil_core/application_record/find_by_like.rb
62
+ - eitil_core/lib/eitil_core/application_record/where_like.rb
63
+ - eitil_core/lib/eitil_core/argument_helpers.rb
64
+ - eitil_core/lib/eitil_core/argument_helpers/all_args_to_ivars.rb
65
+ - eitil_core/lib/eitil_core/argument_helpers/all_kwargs_to_ivars.rb
66
+ - eitil_core/lib/eitil_core/argument_helpers/args_to_ivars.rb
67
+ - eitil_core/lib/eitil_core/concerns.rb
68
+ - eitil_core/lib/eitil_core/concerns/include_concerns_of.rb
69
+ - eitil_core/lib/eitil_core/datetime.rb
70
+ - eitil_core/lib/eitil_core/datetime/prettify.rb
71
+ - eitil_core/lib/eitil_core/errors.rb
72
+ - eitil_core/lib/eitil_core/errors/raise_error.rb
73
+ - eitil_core/lib/eitil_core/float.rb
74
+ - eitil_core/lib/eitil_core/float/safe_to_i.rb
75
+ - eitil_core/lib/eitil_core/hash.rb
76
+ - eitil_core/lib/eitil_core/hash/auto_dig.rb
77
+ - eitil_core/lib/eitil_core/lookups.rb
78
+ - eitil_core/lib/eitil_core/lookups/all_methods.rb
79
+ - eitil_core/lib/eitil_core/railtie.rb
80
+ - eitil_core/lib/eitil_core/safe_executions.rb
81
+ - eitil_core/lib/eitil_core/safe_executions/safe_call.rb
82
+ - eitil_core/lib/eitil_core/safe_executions/safe_send.rb
83
+ - eitil_core/lib/eitil_core/setters.rb
84
+ - eitil_core/lib/eitil_core/setters/set_ivars.rb
85
+ - eitil_core/lib/eitil_core/type_checkers.rb
86
+ - eitil_core/lib/eitil_core/type_checkers/is_num_or_nan.rb
87
+ - eitil_core/lib/eitil_core/validations.rb
88
+ - eitil_core/lib/eitil_core/validations/run_validations.rb
89
+ - eitil_integrate/README.md
90
+ - eitil_integrate/lib/eitil_integrate.rb
91
+ - eitil_integrate/lib/eitil_integrate/railtie.rb
92
+ - eitil_store/README.md
93
+ - eitil_store/lib/eitil_store.rb
94
+ - eitil_store/lib/eitil_store/railtie.rb
95
+ - eitil_store/lib/eitil_store/regex.rb
96
+ - eitil_store/lib/eitil_store/regex/regex.rb
97
+ - eitil_support/README.md
98
+ - eitil_support/lib/eitil_support.rb
99
+ - eitil_support/lib/eitil_support/directory.rb
100
+ - eitil_support/lib/eitil_support/directory/lookups.rb
101
+ - eitil_support/lib/eitil_support/railtie.rb
102
+ - eitil_support/lib/eitil_support/stacktrace.rb
103
+ - eitil_support/lib/eitil_support/stacktrace/audit.rb
104
+ - eitil_support/lib/eitil_support/stacktrace/call.rb
105
+ - eitil_support/lib/eitil_support/stacktrace/stack.rb
106
+ - eitil_wrapper/README.md
107
+ - eitil_wrapper/lib/eitil_wrapper.rb
108
+ - eitil_wrapper/lib/eitil_wrapper/decorators.rb
109
+ - eitil_wrapper/lib/eitil_wrapper/decorators/application_decorator.rb
110
+ - eitil_wrapper/lib/eitil_wrapper/decorators/controller_decorator.rb
111
+ - eitil_wrapper/lib/eitil_wrapper/jobs.rb
112
+ - eitil_wrapper/lib/eitil_wrapper/jobs/new_job.rb
113
+ - eitil_wrapper/lib/eitil_wrapper/jobs/new_job_debugger.rb
114
+ - eitil_wrapper/lib/eitil_wrapper/jobs/single_method_job.rb
115
+ - eitil_wrapper/lib/eitil_wrapper/railtie.rb
116
+ - eitil_wrapper/lib/eitil_wrapper/routes.rb
117
+ - eitil_wrapper/lib/eitil_wrapper/routes/extended_resources.rb
118
+ - eitil_wrapper/lib/eitil_wrapper/scopes.rb
119
+ - eitil_wrapper/lib/eitil_wrapper/scopes/default_scopes.rb
55
120
  - lib/eitil.rb
56
121
  - lib/eitil/all.rb
57
122
  - lib/eitil/engine.rb
@@ -76,9 +141,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
141
  version: '0'
77
142
  required_rubygems_version: !ruby/object:Gem::Requirement
78
143
  requirements:
79
- - - ">"
144
+ - - ">="
80
145
  - !ruby/object:Gem::Version
81
- version: 1.3.1
146
+ version: '0'
82
147
  requirements: []
83
148
  rubygems_version: 3.1.2
84
149
  signing_key: