eitil 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -1
- data/eitil_core/README.md +93 -4
- data/eitil_core/lib/eitil_core.rb +1 -0
- data/eitil_core/lib/eitil_core/application_controller/slice_params.rb +3 -0
- data/eitil_core/lib/eitil_core/application_record/all_associations.rb +3 -0
- data/eitil_core/lib/eitil_core/application_record/find_by_like.rb +3 -0
- data/eitil_core/lib/eitil_core/application_record/where_like.rb +3 -0
- data/eitil_core/lib/eitil_core/argument_helpers.rb +8 -0
- data/eitil_core/lib/eitil_core/argument_helpers/all_args_to_ivars_bang.rb +15 -0
- data/eitil_core/lib/eitil_core/argument_helpers/all_kwargs_to_ivars_bang.rb +15 -0
- data/eitil_core/lib/eitil_core/argument_helpers/args_to_h.rb +15 -0
- data/eitil_core/lib/eitil_core/argument_helpers/args_to_h_bang.rb +17 -0
- data/eitil_core/lib/eitil_core/argument_helpers/args_to_ivars_bang.rb +15 -0
- data/eitil_core/lib/eitil_core/float/safe_to_i.rb +3 -0
- data/eitil_core/lib/eitil_core/lookups.rb +2 -1
- data/eitil_core/lib/eitil_core/lookups/gem_path.rb +10 -0
- data/eitil_core/lib/eitil_core/mocks.rb +6 -0
- data/eitil_core/lib/eitil_core/mocks/array.rb +39 -0
- data/eitil_core/lib/eitil_core/mocks/hash.rb +36 -0
- data/eitil_core/lib/eitil_core/mocks/string.rb +11 -0
- data/eitil_core/lib/eitil_core/railtie.rb +0 -3
- data/eitil_integrate/README.md +11 -0
- data/eitil_integrate/lib/eitil_integrate.rb +4 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter.rb +22 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum.rb +10 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/drop_data.rb +54 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/format_data.rb +27 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/initialize.rb +22 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/present_data.rb +31 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/reduce_data.rb +18 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/sum_data.rb +56 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/default_export.rb +43 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/helpers.rb +50 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/infos.rb +20 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/initialize.rb +28 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/lookups.rb +40 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/selectors.rb +58 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/setters.rb +27 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/store_file.rb +34 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/style_cells.rb +97 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/validations.rb +28 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/write_cells.rb +78 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/write_messages.rb +18 -0
- data/eitil_integrate/lib/eitil_integrate/railtie.rb +0 -3
- data/eitil_store/lib/eitil_store/railtie.rb +0 -3
- data/eitil_support/lib/eitil_support/directory/lookups.rb +3 -0
- data/eitil_support/lib/eitil_support/railtie.rb +0 -3
- data/eitil_wrapper/README.md +16 -0
- data/eitil_wrapper/lib/eitil_wrapper.rb +2 -1
- data/eitil_wrapper/lib/eitil_wrapper/jobs/single_method_job.rb +3 -0
- data/eitil_wrapper/lib/eitil_wrapper/railtie.rb +24 -7
- data/eitil_wrapper/lib/eitil_wrapper/request_logger.rb +5 -0
- data/eitil_wrapper/lib/eitil_wrapper/request_logger/controller_mixin.rb +48 -0
- data/eitil_wrapper/lib/eitil_wrapper/request_logger/logger_job.rb +17 -0
- data/eitil_wrapper/lib/eitil_wrapper/scopes/default_scopes.rb +6 -0
- data/lib/eitil.rb +0 -1
- data/lib/eitil/all.rb +5 -5
- data/lib/eitil/railtie.rb +28 -1
- data/lib/eitil/version.rb +1 -1
- metadata +63 -4
- data/lib/eitil/engine.rb +0 -38
- data/lib/tasks/eitil_tasks.rake +0 -4
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
# require "eitil_integrate/application_exporter/selectors"
|
3
|
+
|
4
|
+
require "eitil_integrate/application_exporter/initialize"
|
5
|
+
|
6
|
+
module EitilIntegrate::RubyXL
|
7
|
+
class ApplicationExporter
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
# rows
|
12
|
+
|
13
|
+
def current_row
|
14
|
+
x
|
15
|
+
end
|
16
|
+
|
17
|
+
def previous_row
|
18
|
+
x - 1
|
19
|
+
end
|
20
|
+
|
21
|
+
def next_row
|
22
|
+
x + 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def first_row
|
26
|
+
0
|
27
|
+
end
|
28
|
+
|
29
|
+
# columns
|
30
|
+
|
31
|
+
def current_column
|
32
|
+
y
|
33
|
+
end
|
34
|
+
|
35
|
+
def previous_column
|
36
|
+
y - 1
|
37
|
+
end
|
38
|
+
|
39
|
+
def next_column
|
40
|
+
y + 1
|
41
|
+
end
|
42
|
+
|
43
|
+
def first_column
|
44
|
+
0
|
45
|
+
end
|
46
|
+
|
47
|
+
# RubyXL object selectors for rows. For columns I have not found a RubyXL object,
|
48
|
+
# or a practical way of accessing the cells of a column, yet.
|
49
|
+
|
50
|
+
def method_missing(_method, *args, &block)
|
51
|
+
m = _method.to_s
|
52
|
+
super _method unless m.include?('row') and m.ends_with?('_object')
|
53
|
+
super _method unless respond_to? m.delete_suffix!('_object'), true
|
54
|
+
sheet[send(m)]
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
# require "eitil_integrate/application_exporter/setters"
|
3
|
+
|
4
|
+
require "eitil_integrate/application_exporter/initialize"
|
5
|
+
|
6
|
+
module EitilIntegrate::RubyXL
|
7
|
+
class ApplicationExporter
|
8
|
+
|
9
|
+
# The date setter methods allow Exporters to receive dates as strings, which are
|
10
|
+
# required to prevent serialization errors in perform_later background jobs.
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def set_start_date
|
15
|
+
@start_date.is_a?(Date) ? @start_date : Date.parse(@start_date) if @start_date
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_end_date
|
19
|
+
@end_date.is_a?(Date) ? @end_date : Date.parse(@end_date) if @end_date
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_date_range
|
23
|
+
@start_date..@end_date if @start_date && @end_date
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
# require "eitil_integrate/application_exporter/store_file"
|
3
|
+
|
4
|
+
require "eitil_integrate/application_exporter/initialize"
|
5
|
+
require "eitil_core/setters/set_ivars"
|
6
|
+
|
7
|
+
module EitilIntegrate::RubyXL
|
8
|
+
class ApplicationExporter
|
9
|
+
|
10
|
+
attr_accessor :storage_path
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def save_file
|
15
|
+
set_ivars :storage_path
|
16
|
+
save_book
|
17
|
+
run_after_save_effects
|
18
|
+
@storage_path
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_storage_path
|
22
|
+
"#{Rails.root}/data/#{self.class.name.snakecase}_#{DateTime.now.prettify}.xlsx"
|
23
|
+
end
|
24
|
+
|
25
|
+
def save_book
|
26
|
+
book.write @storage_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def run_after_save_effects
|
30
|
+
# nil fallback for if the application class (which inherits from ApplicationExporter) has no method #run_after_save_effects
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
|
2
|
+
# require "eitil_integrate/application_exporter/style_cells"
|
3
|
+
|
4
|
+
require "eitil_integrate/application_exporter/initialize"
|
5
|
+
|
6
|
+
module EitilIntegrate::RubyXL
|
7
|
+
class ApplicationExporter
|
8
|
+
|
9
|
+
COLOURS = { white: 'ffffff', black: '000000', red: 'FF0000', blue: '0000FF', green: '00FF00', yellow: 'FFFF00',
|
10
|
+
cyan: '00FFFF', magenta: 'FF00FF', dark_grey: '464646', grey: '7E7E7E', light_grey: 'C1C1C1',
|
11
|
+
eitje_blue: '0496FF' }
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def style_file
|
16
|
+
style_general
|
17
|
+
style_custom
|
18
|
+
end
|
19
|
+
|
20
|
+
def style_general
|
21
|
+
style_row_height
|
22
|
+
style_column_width
|
23
|
+
style_first_row_bold
|
24
|
+
style_first_column_bold
|
25
|
+
end
|
26
|
+
|
27
|
+
def style_custom
|
28
|
+
%i[
|
29
|
+
style_first_x_columns_width
|
30
|
+
style_x_columns_width
|
31
|
+
style_first_x_rows_height
|
32
|
+
style_x_rows_height
|
33
|
+
].each { |_method| safe_send _method }
|
34
|
+
end
|
35
|
+
|
36
|
+
# multi rows
|
37
|
+
|
38
|
+
def style_row_height(height = 15)
|
39
|
+
base_style_x_rows_height row_indices, height
|
40
|
+
end
|
41
|
+
|
42
|
+
def style_first_x_rows_height(n_rows, height)
|
43
|
+
base_style_x_rows_height (0...n_rows), height
|
44
|
+
end
|
45
|
+
|
46
|
+
def style_x_rows_height(row_indices = [], height)
|
47
|
+
row_indices.each { |i| @sheet.change_row_height(i, height) }
|
48
|
+
end
|
49
|
+
|
50
|
+
alias_method :base_style_x_rows_height, :style_x_rows_height
|
51
|
+
|
52
|
+
# multi columns
|
53
|
+
|
54
|
+
def style_column_width(width = 40)
|
55
|
+
base_style_x_columns_width column_indices, width
|
56
|
+
end
|
57
|
+
|
58
|
+
def style_first_x_columns_width(n_columns, width)
|
59
|
+
base_style_x_columns_width (0...n_columns), width
|
60
|
+
end
|
61
|
+
|
62
|
+
def style_x_columns_width(column_indices = [], width)
|
63
|
+
column_indices.each { |i| @sheet.change_column_width(i, width) }
|
64
|
+
end
|
65
|
+
|
66
|
+
alias_method :base_style_x_columns_width, :style_x_columns_width
|
67
|
+
|
68
|
+
# single row
|
69
|
+
|
70
|
+
def style_first_row_bold
|
71
|
+
style_row_bold first_row
|
72
|
+
end
|
73
|
+
|
74
|
+
def style_row_bold(row)
|
75
|
+
@sheet.change_row_bold(row, true)
|
76
|
+
end
|
77
|
+
|
78
|
+
def style_row_font_colour(row, colour)
|
79
|
+
@sheet.change_row_font_color row, COLOURS[colour.to_sym]
|
80
|
+
end
|
81
|
+
|
82
|
+
def style_row_background_colour(row, colour)
|
83
|
+
sheet[row].cells.each { |cell| cell.change_fill COLOURS[colour.to_sym] }
|
84
|
+
end
|
85
|
+
|
86
|
+
# single column
|
87
|
+
|
88
|
+
def style_first_column_bold
|
89
|
+
style_column_bold first_column
|
90
|
+
end
|
91
|
+
|
92
|
+
def style_column_bold(column)
|
93
|
+
@sheet.change_column_bold(column, true)
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
# require "eitil_integrate/application_exporter/validations"
|
3
|
+
|
4
|
+
require "eitil_integrate/application_exporter/initialize"
|
5
|
+
require "eitil_core/errors/raise_error"
|
6
|
+
|
7
|
+
module EitilIntegrate::RubyXL
|
8
|
+
class ApplicationExporter
|
9
|
+
|
10
|
+
def validate_args_presence(*args)
|
11
|
+
args.each do |arg|
|
12
|
+
unless instance_variable_get "@#{arg}"
|
13
|
+
raise_error 'ExportArgumentsNotSetError', 'Set all required arguments. (Be aware that nil values will fail the test.)'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate_args_value
|
20
|
+
# Empty holder to prevent NoMethodError in DefaultExporter#export.
|
21
|
+
end
|
22
|
+
|
23
|
+
def validate_data
|
24
|
+
# Empty holder to prevent NoMethodError in DefaultExporter#export.
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
|
2
|
+
# require "eitil_integrate/application_exporter/write_cells"
|
3
|
+
|
4
|
+
require "eitil_integrate/application_exporter/initialize"
|
5
|
+
|
6
|
+
module EitilIntegrate::RubyXL
|
7
|
+
class ApplicationExporter
|
8
|
+
|
9
|
+
def new_row(row_hash)
|
10
|
+
row_hash.each { |x_axis, title| @sheet.add_cell(x, x_axis.to_s.to_i, title) }
|
11
|
+
@x += 1
|
12
|
+
end
|
13
|
+
|
14
|
+
def empty_row
|
15
|
+
@x += 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def empty_rows(n_rows)
|
19
|
+
@x += n_rows
|
20
|
+
end
|
21
|
+
|
22
|
+
def new_column(column_hash)
|
23
|
+
column_hash.each { |y_axis, title| @sheet.add_cell(y_axis.to_s.to_i, y, title) }
|
24
|
+
@y += 1
|
25
|
+
end
|
26
|
+
|
27
|
+
def empty_column
|
28
|
+
@y += 1
|
29
|
+
end
|
30
|
+
|
31
|
+
def empty_columns(n_columns)
|
32
|
+
@y += n_columns
|
33
|
+
end
|
34
|
+
|
35
|
+
def rows
|
36
|
+
@sheet.sheet_data.rows
|
37
|
+
end
|
38
|
+
|
39
|
+
def row_indices
|
40
|
+
(0...rows.count).to_a
|
41
|
+
end
|
42
|
+
|
43
|
+
def columns
|
44
|
+
# RubyXl does not seem to be purposed around columns, but merely handle rows properly.
|
45
|
+
end
|
46
|
+
|
47
|
+
def column_indices
|
48
|
+
n_rows = rows.map { |r| r&.cells&.count }.compact.max #temporary hack
|
49
|
+
(0...n_rows).to_a
|
50
|
+
end
|
51
|
+
|
52
|
+
def array_to_row(array)
|
53
|
+
new_row array_to_indexed_hash(array)
|
54
|
+
end
|
55
|
+
|
56
|
+
def row_values(row_index)
|
57
|
+
rows.dig(row_index).cells.map &:value
|
58
|
+
end
|
59
|
+
|
60
|
+
def column_values(column_index)
|
61
|
+
rows.map { |row| row&.cells&.dig(column_index)&.value }
|
62
|
+
end
|
63
|
+
|
64
|
+
def all_column_values
|
65
|
+
column_indices.map { |i| { i => column_values(i) } }.inject &:merge
|
66
|
+
end
|
67
|
+
|
68
|
+
def all_row_values
|
69
|
+
row_indices.map { |i| { i => row_values(i) } }.inject &:merge
|
70
|
+
end
|
71
|
+
|
72
|
+
def sum_row
|
73
|
+
new_row EitilIntegrate::RubyXL::AutoSum.perform(all_column_values)
|
74
|
+
style_row_bold previous_row
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
# require "eitil_integrate/application_exporter/write_messages"
|
3
|
+
|
4
|
+
require "eitil_integrate/application_exporter/initialize"
|
5
|
+
|
6
|
+
module EitilIntegrate::RubyXL
|
7
|
+
class ApplicationExporter
|
8
|
+
|
9
|
+
def fill_messages
|
10
|
+
# nil fallback for if the exporter class has no method #fill_messages
|
11
|
+
end
|
12
|
+
|
13
|
+
def write_message(message)
|
14
|
+
new_row({ '0': message })
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/eitil_wrapper/README.md
CHANGED
@@ -179,3 +179,19 @@ Scopes are generated through the columns of your model's database table. Which s
|
|
179
179
|
```
|
180
180
|
|
181
181
|
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
## EitilWrapper::RequestLogger
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
|
189
|
+
require "eitil_wrapper/request_logger"
|
190
|
+
|
191
|
+
```
|
192
|
+
|
193
|
+
The RequestLogger wrapper logs request params in /log/request_logger.log, which offers the opportunity to pry into webhooks while developing. In order to track a controller, simply include EitilWrapper::RequestLogger::ControllerMixin. This calls a background job which writes to the file.
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
@@ -2,6 +2,9 @@
|
|
2
2
|
# somehow leads to errors in the initialization process. Ideally, this code would be
|
3
3
|
# defined in eitil_wrapper/jobs/single_method_job.rb and dispatched in eitil_wrapper/railtie.rb
|
4
4
|
|
5
|
+
# require "eitil_wrapper/railtie" to run the dynamic dispatch as an init hook during boot
|
6
|
+
require "eitil_wrapper/railtie"
|
7
|
+
|
5
8
|
module EitilWrapper
|
6
9
|
module CreateSingleMethodJob
|
7
10
|
end
|
@@ -1,22 +1,17 @@
|
|
1
1
|
|
2
|
-
require "rails"
|
3
|
-
require "eitil_wrapper"
|
4
|
-
|
5
2
|
module EitilWrapper
|
6
3
|
|
7
4
|
class Railtie < Rails::Railtie
|
8
5
|
|
6
|
+
# Dynamic dispatching after initialization of Rails classes.
|
7
|
+
|
9
8
|
initializer "my_railtie.configure_rails_initialization", options: :after do |app|
|
10
9
|
|
11
|
-
# Dynamic dispatching after initialization of Rails classes.
|
12
10
|
|
13
|
-
# Scopes
|
14
|
-
|
15
11
|
if Object.const_defined?('EitilWrapper::Scopes::DefaultScopes')
|
16
12
|
::ApplicationRecord.send(:extend, EitilWrapper::Scopes::DefaultScopes)
|
17
13
|
end
|
18
14
|
|
19
|
-
# Jobs
|
20
15
|
|
21
16
|
if Object.const_defined?('EitilWrapper::CreateSingleMethodJob')
|
22
17
|
|
@@ -44,6 +39,28 @@ module EitilWrapper
|
|
44
39
|
object.send _method, *args, **kwargs
|
45
40
|
end; end; end; end
|
46
41
|
|
42
|
+
|
43
|
+
if Object.const_defined?('EitilWrapper::RequestLogger::CreateLoggerJob')
|
44
|
+
|
45
|
+
module ::EitilWrapper
|
46
|
+
module RequestLogger
|
47
|
+
class LoggerJob < ::ApplicationJob
|
48
|
+
|
49
|
+
def perform(logger_object)
|
50
|
+
|
51
|
+
# set path for logger
|
52
|
+
$request_logger_path ||= "#{Rails.root}/log/request_logger.log"
|
53
|
+
|
54
|
+
# create logger, if not present
|
55
|
+
if Dir[$request_logger_path].blank? || $request_logger.blank?
|
56
|
+
$request_logger = Logger.new($request_logger_path)
|
57
|
+
end
|
58
|
+
|
59
|
+
# add logger_object to logger
|
60
|
+
$request_logger.info(logger_object)
|
61
|
+
|
62
|
+
end; end; end; end; end
|
63
|
+
|
47
64
|
end
|
48
65
|
end
|
49
66
|
end
|