eitil 1.4.1 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/eitil_integrate/lib/eitil_integrate/application_exporter/lookups.rb +1 -1
- data/lib/eitil/railtie.rb +2 -3
- data/lib/eitil/version.rb +1 -1
- data/spec/dummy_app/app/controllers/application_controller.rb +0 -2
- data/spec/dummy_app/app/controllers/users_controller.rb +0 -31
- data/spec/dummy_app/config/routes.rb +0 -5
- data/spec/dummy_app/db/test.sqlite3 +0 -0
- data/spec/spec_helper.rb +0 -2
- metadata +2 -27
- data/eitil_wrapper/README.md +0 -309
- data/eitil_wrapper/lib/eitil_wrapper/callbacks/helper_methods.rb +0 -118
- data/eitil_wrapper/lib/eitil_wrapper/callbacks.rb +0 -2
- data/eitil_wrapper/lib/eitil_wrapper/decorators/application_decorator.rb +0 -22
- data/eitil_wrapper/lib/eitil_wrapper/decorators/controller_decorator.rb +0 -72
- data/eitil_wrapper/lib/eitil_wrapper/decorators.rb +0 -3
- data/eitil_wrapper/lib/eitil_wrapper/jobs/new_job.rb +0 -34
- data/eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb +0 -37
- data/eitil_wrapper/lib/eitil_wrapper/jobs/single_method_job.rb +0 -11
- data/eitil_wrapper/lib/eitil_wrapper/jobs.rb +0 -4
- data/eitil_wrapper/lib/eitil_wrapper/railtie.rb +0 -94
- data/eitil_wrapper/lib/eitil_wrapper/records/default_calculators.rb +0 -104
- data/eitil_wrapper/lib/eitil_wrapper/records/default_scopes.rb +0 -95
- data/eitil_wrapper/lib/eitil_wrapper/records/default_sorts.rb +0 -81
- data/eitil_wrapper/lib/eitil_wrapper/records.rb +0 -4
- data/eitil_wrapper/lib/eitil_wrapper/request_logger/controller_mixin.rb +0 -48
- data/eitil_wrapper/lib/eitil_wrapper/request_logger/logger_job.rb +0 -17
- data/eitil_wrapper/lib/eitil_wrapper/request_logger.rb +0 -5
- data/eitil_wrapper/lib/eitil_wrapper/routes/extended_resources.rb +0 -40
- data/eitil_wrapper/lib/eitil_wrapper/routes.rb +0 -2
- data/eitil_wrapper/lib/eitil_wrapper.rb +0 -9
- data/spec/dummy_app/app/decorators/address_decorator.rb +0 -3
- data/spec/dummy_app/app/decorators/application_decorator.rb +0 -12
- data/spec/dummy_app/app/decorators/user_decorator.rb +0 -19
- data/spec/eitil_wrapper/decorators/decorators_spec.rb +0 -49
@@ -1,72 +0,0 @@
|
|
1
|
-
module EitilWrapper
|
2
|
-
module ControllerDecorator
|
3
|
-
|
4
|
-
private
|
5
|
-
|
6
|
-
def decorate(dec_item, dec_method: nil, dec_class: nil, **dec_kwargs)
|
7
|
-
all_args_to_ivars binding
|
8
|
-
set_ivars :dec_class, :decorator, :dec_method
|
9
|
-
send_to_decorator
|
10
|
-
|
11
|
-
rescue NameError => e
|
12
|
-
puts "EitilWrapper::ControllerDecorator => rescuing uninitialised constant #{e.name}, returning the object's default JSON instead."
|
13
|
-
return dec_item.as_json
|
14
|
-
end
|
15
|
-
|
16
|
-
def send_to_decorator
|
17
|
-
@decorator.send(@dec_method, @dec_item)
|
18
|
-
|
19
|
-
rescue NoMethodError => e
|
20
|
-
inform_no_method_for_decorator_error
|
21
|
-
@dec_item
|
22
|
-
end
|
23
|
-
|
24
|
-
def inform_no_method_for_decorator_error
|
25
|
-
message = "Warning: NoMethodError for #{@dec_class}##{@dec_method}, returned @dec_item instead."
|
26
|
-
Logger.new("#{Rails.root}/log/decorator_log.log").warn message
|
27
|
-
warn message
|
28
|
-
end
|
29
|
-
|
30
|
-
def set_dec_method
|
31
|
-
@dec_method = @dec_method || derived_dec_method || :base
|
32
|
-
end
|
33
|
-
|
34
|
-
def derived_dec_method
|
35
|
-
return unless respond_to? :params
|
36
|
-
return :app if @decorator.respond_to?(:app) && params["isMobile"]
|
37
|
-
return :web if @decorator.respond_to?(:web) && params["isWeb"]
|
38
|
-
end
|
39
|
-
|
40
|
-
def set_dec_class
|
41
|
-
@dec_class = @dec_class ? manual_set_dec_class : derived_dec_class
|
42
|
-
end
|
43
|
-
|
44
|
-
def manual_set_dec_class
|
45
|
-
"#{@dec_class}Decorator".constantize
|
46
|
-
end
|
47
|
-
|
48
|
-
def derived_dec_class
|
49
|
-
"#{@dec_item.class.name}Decorator".constantize
|
50
|
-
end
|
51
|
-
|
52
|
-
def set_decorator
|
53
|
-
@dec_class.new **ivars
|
54
|
-
end
|
55
|
-
|
56
|
-
# Converts the controller_ivars, given in your main application's configuration,
|
57
|
-
# into an hash. If no controller_ivars, continue with converting, in order to avoid
|
58
|
-
# issues due to differing data types.
|
59
|
-
def controller_ivars
|
60
|
-
return {} unless Eitil.controller_ivars.any?
|
61
|
-
|
62
|
-
Eitil.controller_ivars.map do |ivar|
|
63
|
-
{ ivar => instance_variable_get("@#{ivar.to_s}") }
|
64
|
-
end.inject &:merge
|
65
|
-
end
|
66
|
-
|
67
|
-
def ivars
|
68
|
-
@dec_kwargs.any? ? controller_ivars.merge(@dec_kwargs) : controller_ivars
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
@@ -1,34 +0,0 @@
|
|
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
|
@@ -1,37 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_wrapper/jobs/new_job_now"
|
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_now(_method, *args, **kwargs)
|
18
|
-
|
19
|
-
if instance_methods(false).include? _method
|
20
|
-
define_method "#{_method}_job_now" 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_now" 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
|
@@ -1,11 +0,0 @@
|
|
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
|
-
# require "eitil_wrapper/railtie" to run the dynamic dispatch as an init hook during boot
|
6
|
-
require "eitil_wrapper/railtie"
|
7
|
-
|
8
|
-
module EitilWrapper
|
9
|
-
module CreateSingleMethodJob
|
10
|
-
end
|
11
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
|
2
|
-
module EitilWrapper
|
3
|
-
|
4
|
-
class Railtie < Rails::Railtie
|
5
|
-
|
6
|
-
# Dynamic dispatching after initialization of Rails classes.
|
7
|
-
|
8
|
-
initializer "my_railtie.configure_rails_initialization", options: :after do |app|
|
9
|
-
|
10
|
-
if Object.const_defined?('EitilWrapper::Records::DefaultCalculators')
|
11
|
-
::ApplicationRecord.send(:extend, EitilWrapper::Records::DefaultCalculators)
|
12
|
-
end
|
13
|
-
|
14
|
-
if Object.const_defined?('EitilWrapper::Records::DefaultScopes')
|
15
|
-
::ApplicationRecord.send(:extend, EitilWrapper::Records::DefaultScopes)
|
16
|
-
end
|
17
|
-
|
18
|
-
if Object.const_defined?('EitilWrapper::Records::DefaultSorts')
|
19
|
-
::ApplicationRecord.send(:extend, EitilWrapper::Records::DefaultSorts)
|
20
|
-
end
|
21
|
-
|
22
|
-
if Object.const_defined?('EitilWrapper::Callbacks::HelperMethods')
|
23
|
-
::ApplicationRecord.send(:extend, EitilWrapper::Callbacks::HelperMethods)
|
24
|
-
end
|
25
|
-
|
26
|
-
if Object.const_defined?('EitilWrapper::CreateSingleMethodJob')
|
27
|
-
|
28
|
-
# ISSUE: this code is currently defined eitil_wrapper/railtie.rb, since module inclusion
|
29
|
-
# somehow leads to errors in the initialization process. Ideally, this code would be
|
30
|
-
# defined in eitil_wrapper/jobs/single_method_job.rb and dispatched in eitil_wrapper/railtie.rb
|
31
|
-
|
32
|
-
# BEWARE: _self is currently not accepted in perform_later jobs due to serialization errors
|
33
|
-
|
34
|
-
# BEWARE: The cases of 'id' and '_self' both handle instances, with the difference
|
35
|
-
# being that 'id' works for objects that have a database record, while '_self'
|
36
|
-
# works for non database supported instanes, such as an Exporter instance.
|
37
|
-
|
38
|
-
module ::EitilWrapper
|
39
|
-
|
40
|
-
class ::ApplicationJob < ActiveJob::Base
|
41
|
-
end
|
42
|
-
|
43
|
-
class SingleMethodJob < ::ApplicationJob
|
44
|
-
def perform(*args, _class:, _method:, id: nil, _self: nil, **kwargs)
|
45
|
-
object =
|
46
|
-
if id
|
47
|
-
_class.constantize.find(id)
|
48
|
-
elsif _self
|
49
|
-
_self
|
50
|
-
else
|
51
|
-
_class.constantize
|
52
|
-
end
|
53
|
-
|
54
|
-
if args.present? and kwargs.present?
|
55
|
-
object.send _method, *args, **kwargs
|
56
|
-
|
57
|
-
elsif args.present?
|
58
|
-
object.send _method, *args
|
59
|
-
|
60
|
-
elsif kwargs.present?
|
61
|
-
object.send _method, **kwargs
|
62
|
-
|
63
|
-
else
|
64
|
-
object.send _method
|
65
|
-
end
|
66
|
-
|
67
|
-
end; end; end; end
|
68
|
-
|
69
|
-
|
70
|
-
if Object.const_defined?('EitilWrapper::RequestLogger::CreateLoggerJob')
|
71
|
-
|
72
|
-
module ::EitilWrapper
|
73
|
-
module RequestLogger
|
74
|
-
class LoggerJob < ::ApplicationJob
|
75
|
-
|
76
|
-
def perform(logger_object)
|
77
|
-
|
78
|
-
# set path for logger
|
79
|
-
$request_logger_path ||= "#{Rails.root}/log/request_logger.log"
|
80
|
-
|
81
|
-
# create logger, if not present
|
82
|
-
if Dir[$request_logger_path].blank? || $request_logger.blank?
|
83
|
-
$request_logger = Logger.new($request_logger_path)
|
84
|
-
end
|
85
|
-
|
86
|
-
# add logger_object to logger
|
87
|
-
$request_logger.info(logger_object)
|
88
|
-
|
89
|
-
end; end; end; end; end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_wrapper/records/default_calculators"
|
3
|
-
|
4
|
-
# require "eitil_wrapper/railtie" to run the dynamic dispatch as an init hook during boot
|
5
|
-
require "eitil_wrapper/railtie"
|
6
|
-
|
7
|
-
module EitilWrapper
|
8
|
-
module Records
|
9
|
-
module DefaultCalculators
|
10
|
-
|
11
|
-
Eitil::ApplicationRecordModules << self
|
12
|
-
|
13
|
-
SharableNumberCalculators = -> (_class, column) {
|
14
|
-
_class.eitil_calculator :"#{column}_max", -> { _class.maximum(column) }
|
15
|
-
_class.eitil_calculator :"#{column}_min", -> { _class.minimum(column) }
|
16
|
-
_class.eitil_calculator :"#{column}_sum", -> { _class.sum(column) }
|
17
|
-
_class.eitil_calculator :"#{column}_avg", -> { _class.average(column) }
|
18
|
-
}
|
19
|
-
|
20
|
-
SharableIterableCalculators = -> (_class, column) {
|
21
|
-
_class.eitil_calculator :"#{column}_sum", -> { _class.pluck(column).flatten!.uniq }
|
22
|
-
_class.eitil_calculator :"#{column}_sum_i", -> { _class.pluck(column).flatten!.uniq.map(&:to_i) }
|
23
|
-
_class.eitil_calculator :"#{column}_sum_f", -> { _class.pluck(column).flatten!.uniq.map(&:to_f) }
|
24
|
-
_class.eitil_calculator :"#{column}_sum_d", -> { _class.pluck(column).flatten!.uniq.map(&:to_d) }
|
25
|
-
}
|
26
|
-
|
27
|
-
def inherited(subclass)
|
28
|
-
super
|
29
|
-
return if Eitil.skip_default_calculators_for_models.include?(subclass.to_s.to_sym)
|
30
|
-
|
31
|
-
# Set the proper table_names for namespaced models. Without setting this,
|
32
|
-
# Rails run into problems due to the fact that the first call to the model's
|
33
|
-
# constant triggers this initializer first, and only thereafter the model file
|
34
|
-
# which sets the correct table_name through a macro.
|
35
|
-
|
36
|
-
namespaced_class = subclass.to_s.include?('::')
|
37
|
-
subclass.table_name = subclass.to_s.gsub('::', '_').downcase.pluralize if namespaced_class
|
38
|
-
|
39
|
-
subclass.use_eitil_calculators
|
40
|
-
|
41
|
-
rescue => e
|
42
|
-
puts "default calculators failed for class '#{subclass}' with expected table '#{subclass.table_name}' because of #{e.class} and '#{e.to_s.split(' ').first}'"
|
43
|
-
end
|
44
|
-
|
45
|
-
def use_eitil_calculators
|
46
|
-
return if abstract_class?
|
47
|
-
|
48
|
-
# text[] is postgresql's datatype for serialized arrays
|
49
|
-
# numeric is postgresql's datatype for decimals
|
50
|
-
# double precision is postgresql's datatype for floats
|
51
|
-
|
52
|
-
|
53
|
-
%w[integer bigint double\ precision numeric].each do |_type|
|
54
|
-
send :"create_eitil_#{_type.gsub(' ','_')}_calculators"
|
55
|
-
end
|
56
|
-
|
57
|
-
create_array_calculators
|
58
|
-
end
|
59
|
-
|
60
|
-
def eitil_calculator(_name, _proc)
|
61
|
-
# skip calculator methods for primary and foreign key columns
|
62
|
-
return if _name.to_s =~ /^id_[a-z]{1,}$/ || _name.to_s =~ /_id_[a-z]{1,}$/
|
63
|
-
|
64
|
-
define_singleton_method(_name) { _proc.call } unless respond_to? _name
|
65
|
-
end
|
66
|
-
|
67
|
-
def calculator_columns_of_type(data_type)
|
68
|
-
columns_hash.select { |column,v| v.sql_type == data_type }
|
69
|
-
end
|
70
|
-
|
71
|
-
def create_eitil_integer_calculators
|
72
|
-
calculator_columns_of_type("integer")&.map do |column, object|
|
73
|
-
SharableNumberCalculators.call self, column
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def create_eitil_bigint_calculators
|
78
|
-
calculator_columns_of_type("bigint")&.map do |column, object|
|
79
|
-
SharableNumberCalculators.call self, column
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def create_eitil_double_precision_calculators
|
84
|
-
calculator_columns_of_type("double\ precision")&.map do |column, object|
|
85
|
-
SharableNumberCalculators.call self, column
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def create_eitil_numeric_calculators
|
90
|
-
calculator_columns_of_type("numeric")&.map do |column, object|
|
91
|
-
SharableNumberCalculators.call self, column
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def create_array_calculators
|
96
|
-
columns = columns_hash.select { |column,v| v.sql_type == "text" && v.default == "{}" }
|
97
|
-
columns&.map do |column, object|
|
98
|
-
SharableIterableCalculators.call self, column
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_wrapper/records/default_scopes"
|
3
|
-
|
4
|
-
# require "eitil_wrapper/railtie" to run the dynamic dispatch as an init hook during boot
|
5
|
-
require "eitil_wrapper/railtie"
|
6
|
-
|
7
|
-
module EitilWrapper
|
8
|
-
module Records
|
9
|
-
module DefaultScopes
|
10
|
-
|
11
|
-
Eitil::ApplicationRecordModules << self
|
12
|
-
|
13
|
-
SharableDateScopes = -> (_class, column) {
|
14
|
-
_class.eitil_scope :"#{column}_today", -> { where("#{column} = ?", Date.today) }
|
15
|
-
_class.eitil_scope :"#{column}_past", -> { where("#{column} < ?", Date.today) }
|
16
|
-
_class.eitil_scope :"#{column}_future", -> { where("#{column} > ?", Date.today) }
|
17
|
-
|
18
|
-
_class.eitil_scope :"#{column}_on_date", -> (date) { where("#{column} = ?", date) }
|
19
|
-
_class.eitil_scope :"#{column}_before_date", -> (date) { where("#{column} = ?", date) }
|
20
|
-
_class.eitil_scope :"#{column}_after_date", -> (date) { where("#{column} = ?", date) }
|
21
|
-
_class.eitil_scope :"#{column}_between_dates", -> (from, till) { where("#{column} >= ? and #{column} <= ?", from, till) }
|
22
|
-
}
|
23
|
-
|
24
|
-
SharableNumScopes = -> (_class, column) {
|
25
|
-
_class.eitil_scope :"#{column}_equal_to", -> (number) { where("#{column} = ?", number) }
|
26
|
-
_class.eitil_scope :"#{column}_lower_than", -> (number) { where("#{column} = <", number) }
|
27
|
-
_class.eitil_scope :"#{column}_higher_than", -> (number) { where("#{column} = >", number) }
|
28
|
-
_class.eitil_scope :"#{column}_between", -> (min, max) { where("#{column} >= ? and #{column} <= ?", min, max) }
|
29
|
-
}
|
30
|
-
|
31
|
-
def inherited(subclass)
|
32
|
-
super
|
33
|
-
return if Eitil.skip_default_scopes_for_models.include?(subclass.to_s.to_sym)
|
34
|
-
|
35
|
-
# Set the proper table_names for namespaced models. Without setting this,
|
36
|
-
# Rails run into problems due to the fact that the first call to the model's
|
37
|
-
# constant triggers this initializer first, and only thereafter the model file
|
38
|
-
# which sets the correct table_name through a macro.
|
39
|
-
|
40
|
-
namespaced_class = subclass.to_s.include?('::')
|
41
|
-
subclass.table_name = subclass.to_s.gsub('::', '_').downcase.pluralize if namespaced_class
|
42
|
-
|
43
|
-
subclass.use_eitil_scopes
|
44
|
-
|
45
|
-
rescue => e
|
46
|
-
puts "default scopes failed for class '#{subclass}' with expected table '#{subclass.table_name}' because of #{e.class} and '#{e.to_s.split(' ').first}'"
|
47
|
-
end
|
48
|
-
|
49
|
-
def use_eitil_scopes
|
50
|
-
return if abstract_class?
|
51
|
-
%i[boolean datetime date integer float].each { |_type| send :"create_eitil_#{_type}_scopes" }
|
52
|
-
end
|
53
|
-
|
54
|
-
def eitil_scope(_name, _proc)
|
55
|
-
scope _name, _proc unless respond_to? _name
|
56
|
-
end
|
57
|
-
|
58
|
-
def columns_of_type(data_type)
|
59
|
-
columns_hash.select { |column,v| v.sql_type_metadata.type == data_type }
|
60
|
-
end
|
61
|
-
|
62
|
-
def create_eitil_boolean_scopes
|
63
|
-
columns_of_type(:boolean)&.map do |column, object|
|
64
|
-
eitil_scope :"#{column}_true", -> { where(column => true) }
|
65
|
-
eitil_scope :"#{column}_false", -> { where(column => [false, nil]) }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def create_eitil_datetime_scopes
|
70
|
-
columns_of_type(:datetime)&.map do |column, object|
|
71
|
-
SharableDateScopes.call self, column
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def create_eitil_date_scopes
|
76
|
-
columns_of_type(:date)&.map do |column, object|
|
77
|
-
SharableDateScopes.call self, column
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def create_eitil_integer_scopes
|
82
|
-
columns_of_type(:integer)&.map do |column, object|
|
83
|
-
SharableNumScopes.call self, column
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def create_eitil_float_scopes
|
88
|
-
columns_of_type(:float)&.map do |column, object|
|
89
|
-
SharableNumScopes.call self, column
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_wrapper/records/default_sorts"
|
3
|
-
|
4
|
-
# require "eitil_wrapper/railtie" to run the dynamic dispatch as an init hook during boot
|
5
|
-
require "eitil_wrapper/railtie"
|
6
|
-
|
7
|
-
|
8
|
-
module EitilWrapper
|
9
|
-
module Records
|
10
|
-
module DefaultSorts
|
11
|
-
|
12
|
-
Eitil::ApplicationRecordModules << self
|
13
|
-
|
14
|
-
SharableDateSorts = -> (_class, column) {
|
15
|
-
_class.eitil_sort :"#{column}_oldest_first", -> { _class.order("#{column} ASC") }
|
16
|
-
_class.eitil_sort :"#{column}_newest_first", -> { _class.order("#{column} DESC") }
|
17
|
-
}
|
18
|
-
|
19
|
-
SharableNumSorts = -> (_class, column) {
|
20
|
-
_class.eitil_sort :"#{column}_ascending", -> { _class.order("#{column} ASC") }
|
21
|
-
_class.eitil_sort :"#{column}_descending", -> { _class.order("#{column} DESC") }
|
22
|
-
}
|
23
|
-
|
24
|
-
def inherited(subclass)
|
25
|
-
super
|
26
|
-
return if Eitil.skip_default_sorts_for_models.include?(subclass.to_s.to_sym)
|
27
|
-
|
28
|
-
# Set the proper table_names for namespaced models. Without setting this,
|
29
|
-
# Rails run into problems due to the fact that the first call to the model's
|
30
|
-
# constant triggers this initializer first, and only thereafter the model file
|
31
|
-
# which sets the correct table_name through a macro.
|
32
|
-
|
33
|
-
namespaced_class = subclass.to_s.include?('::')
|
34
|
-
subclass.table_name = subclass.to_s.gsub('::', '_').downcase.pluralize if namespaced_class
|
35
|
-
|
36
|
-
subclass.use_eitil_sorts
|
37
|
-
|
38
|
-
rescue => e
|
39
|
-
puts "default sorts failed for class '#{subclass}' with expected table '#{subclass.table_name}' because of #{e.class} and '#{e.to_s.split(' ').first}'"
|
40
|
-
end
|
41
|
-
|
42
|
-
def use_eitil_sorts
|
43
|
-
return if abstract_class?
|
44
|
-
%i[datetime date integer float].each { |_type| send :"create_eitil_#{_type}_sorts" }
|
45
|
-
end
|
46
|
-
|
47
|
-
def eitil_sort(_name, _proc)
|
48
|
-
define_singleton_method(_name) { _proc.call } unless respond_to? _name
|
49
|
-
end
|
50
|
-
|
51
|
-
def sort_columns_of_type(data_type)
|
52
|
-
columns_hash.select { |column,v| v.sql_type_metadata.type == data_type }
|
53
|
-
end
|
54
|
-
|
55
|
-
def create_eitil_datetime_sorts
|
56
|
-
columns_of_type(:datetime)&.map do |column, object|
|
57
|
-
SharableDateSorts.call self, column
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def create_eitil_date_sorts
|
62
|
-
columns_of_type(:date)&.map do |column, object|
|
63
|
-
SharableDateSorts.call self, column
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def create_eitil_integer_sorts
|
68
|
-
columns_of_type(:integer)&.map do |column, object|
|
69
|
-
SharableNumSorts.call self, column
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def create_eitil_float_sorts
|
74
|
-
columns_of_type(:float)&.map do |column, object|
|
75
|
-
SharableNumSorts.call self, column
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_wrapper/request_logger/controller_mixin"
|
3
|
-
|
4
|
-
require_relative "logger_job"
|
5
|
-
|
6
|
-
module EitilWrapper
|
7
|
-
module RequestLogger
|
8
|
-
module ControllerMixin
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def log_request
|
13
|
-
$request_logger_path ||= "#{Rails.root}/log/request_logger.log"
|
14
|
-
EitilWrapper::RequestLogger::LoggerJob.perform_later(request_logger_object)
|
15
|
-
end
|
16
|
-
|
17
|
-
def request_logger_object
|
18
|
-
|
19
|
-
log_request = {
|
20
|
-
path: request.env["REQUEST_PATH"],
|
21
|
-
method: request.env["REQUEST_METHOD"],
|
22
|
-
query_str: request.env["QUERY_STRING"],
|
23
|
-
}
|
24
|
-
|
25
|
-
log_params = {
|
26
|
-
params: params.as_json
|
27
|
-
}
|
28
|
-
|
29
|
-
log_attributes = {
|
30
|
-
time: Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
31
|
-
}
|
32
|
-
|
33
|
-
log = {
|
34
|
-
request: log_request,
|
35
|
-
params: log_params,
|
36
|
-
attributes: log_attributes
|
37
|
-
}
|
38
|
-
|
39
|
-
log_time = log_attributes[:time]
|
40
|
-
log_strf = log.deep_symbolize_keys.to_s
|
41
|
-
# log_strf may be hashed through eval(log_strf)
|
42
|
-
|
43
|
-
return log_strf
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_wrapper/request_logger/logger_job"
|
3
|
-
|
4
|
-
# require "eitil_wrapper/railtie" to run the dynamic dispatch as an init hook during boot
|
5
|
-
require "eitil_wrapper/railtie"
|
6
|
-
|
7
|
-
# ISSUE: this code is currently defined eitil_wrapper/railtie.rb, since module inclusion
|
8
|
-
# somehow leads to errors in the initialization process. Ideally, this code would be
|
9
|
-
# defined in eitil_wrapper/request_logger/logger_job.rb and dispatched in eitil_wrapper/railtie.rb
|
10
|
-
|
11
|
-
module EitilWrapper
|
12
|
-
module RequestLogger
|
13
|
-
module CreateLoggerJob
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,40 +0,0 @@
|
|
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
|