eitil 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -1
  3. data/eitil_core/README.md +93 -4
  4. data/eitil_core/lib/eitil_core.rb +1 -0
  5. data/eitil_core/lib/eitil_core/application_controller/slice_params.rb +3 -0
  6. data/eitil_core/lib/eitil_core/application_record/all_associations.rb +3 -0
  7. data/eitil_core/lib/eitil_core/application_record/find_by_like.rb +3 -0
  8. data/eitil_core/lib/eitil_core/application_record/where_like.rb +3 -0
  9. data/eitil_core/lib/eitil_core/argument_helpers.rb +8 -0
  10. data/eitil_core/lib/eitil_core/argument_helpers/all_args_to_ivars_bang.rb +15 -0
  11. data/eitil_core/lib/eitil_core/argument_helpers/all_kwargs_to_ivars_bang.rb +15 -0
  12. data/eitil_core/lib/eitil_core/argument_helpers/args_to_h.rb +15 -0
  13. data/eitil_core/lib/eitil_core/argument_helpers/args_to_h_bang.rb +17 -0
  14. data/eitil_core/lib/eitil_core/argument_helpers/args_to_ivars_bang.rb +15 -0
  15. data/eitil_core/lib/eitil_core/float/safe_to_i.rb +3 -0
  16. data/eitil_core/lib/eitil_core/lookups.rb +2 -1
  17. data/eitil_core/lib/eitil_core/lookups/gem_path.rb +10 -0
  18. data/eitil_core/lib/eitil_core/mocks.rb +6 -0
  19. data/eitil_core/lib/eitil_core/mocks/array.rb +39 -0
  20. data/eitil_core/lib/eitil_core/mocks/hash.rb +36 -0
  21. data/eitil_core/lib/eitil_core/mocks/string.rb +11 -0
  22. data/eitil_core/lib/eitil_core/railtie.rb +0 -3
  23. data/eitil_integrate/README.md +11 -0
  24. data/eitil_integrate/lib/eitil_integrate.rb +4 -0
  25. data/eitil_integrate/lib/eitil_integrate/application_exporter.rb +22 -0
  26. data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum.rb +10 -0
  27. data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/drop_data.rb +54 -0
  28. data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/format_data.rb +27 -0
  29. data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/initialize.rb +22 -0
  30. data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/present_data.rb +31 -0
  31. data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/reduce_data.rb +18 -0
  32. data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/sum_data.rb +56 -0
  33. data/eitil_integrate/lib/eitil_integrate/application_exporter/default_export.rb +43 -0
  34. data/eitil_integrate/lib/eitil_integrate/application_exporter/helpers.rb +50 -0
  35. data/eitil_integrate/lib/eitil_integrate/application_exporter/infos.rb +20 -0
  36. data/eitil_integrate/lib/eitil_integrate/application_exporter/initialize.rb +28 -0
  37. data/eitil_integrate/lib/eitil_integrate/application_exporter/lookups.rb +40 -0
  38. data/eitil_integrate/lib/eitil_integrate/application_exporter/selectors.rb +58 -0
  39. data/eitil_integrate/lib/eitil_integrate/application_exporter/setters.rb +27 -0
  40. data/eitil_integrate/lib/eitil_integrate/application_exporter/store_file.rb +34 -0
  41. data/eitil_integrate/lib/eitil_integrate/application_exporter/style_cells.rb +97 -0
  42. data/eitil_integrate/lib/eitil_integrate/application_exporter/validations.rb +28 -0
  43. data/eitil_integrate/lib/eitil_integrate/application_exporter/write_cells.rb +78 -0
  44. data/eitil_integrate/lib/eitil_integrate/application_exporter/write_messages.rb +18 -0
  45. data/eitil_integrate/lib/eitil_integrate/railtie.rb +0 -3
  46. data/eitil_store/lib/eitil_store/railtie.rb +0 -3
  47. data/eitil_support/lib/eitil_support/directory/lookups.rb +3 -0
  48. data/eitil_support/lib/eitil_support/railtie.rb +0 -3
  49. data/eitil_wrapper/README.md +16 -0
  50. data/eitil_wrapper/lib/eitil_wrapper.rb +2 -1
  51. data/eitil_wrapper/lib/eitil_wrapper/jobs/single_method_job.rb +3 -0
  52. data/eitil_wrapper/lib/eitil_wrapper/railtie.rb +24 -7
  53. data/eitil_wrapper/lib/eitil_wrapper/request_logger.rb +5 -0
  54. data/eitil_wrapper/lib/eitil_wrapper/request_logger/controller_mixin.rb +48 -0
  55. data/eitil_wrapper/lib/eitil_wrapper/request_logger/logger_job.rb +17 -0
  56. data/eitil_wrapper/lib/eitil_wrapper/scopes/default_scopes.rb +6 -0
  57. data/lib/eitil.rb +0 -1
  58. data/lib/eitil/all.rb +5 -5
  59. data/lib/eitil/railtie.rb +28 -1
  60. data/lib/eitil/version.rb +1 -1
  61. metadata +63 -4
  62. data/lib/eitil/engine.rb +0 -38
  63. data/lib/tasks/eitil_tasks.rake +0 -4
@@ -0,0 +1,4 @@
1
+
2
+ # require "eitil_integrate"
3
+
4
+ require "eitil_integrate/application_exporter"
@@ -0,0 +1,22 @@
1
+ # require "eitil_integrate/application_exporter"
2
+
3
+ # base file, which is required by all others
4
+ require_relative "application_exporter/initialize"
5
+
6
+ # temp file, with methods that should, at some point, moved elsewhere
7
+ require_relative "application_exporter/helpers"
8
+
9
+ # files split by theme and purpose, feel free to cherry-pick
10
+ require_relative "application_exporter/default_export"
11
+ require_relative "application_exporter/validations"
12
+ require_relative "application_exporter/write_cells"
13
+ require_relative "application_exporter/write_messages"
14
+ require_relative "application_exporter/style_cells"
15
+ require_relative "application_exporter/store_file"
16
+ require_relative "application_exporter/setters"
17
+ require_relative "application_exporter/selectors"
18
+ require_relative "application_exporter/lookups"
19
+ require_relative "application_exporter/infos"
20
+
21
+ # the AutoSum module, which is a seperately functioning module (service)
22
+ require_relative "application_exporter/auto_sum"
@@ -0,0 +1,10 @@
1
+
2
+ # require "eitil_integrate/application_exporter/auto_sum"
3
+
4
+ require_relative "auto_sum/initialize"
5
+
6
+ require_relative "auto_sum/drop_data"
7
+ require_relative "auto_sum/format_data"
8
+ require_relative "auto_sum/reduce_data"
9
+ require_relative "auto_sum/sum_data"
10
+ require_relative "auto_sum/present_data"
@@ -0,0 +1,54 @@
1
+
2
+ # require "eitil_integrate/application_exporter/auto_sum/drop_data"
3
+
4
+ module EitilIntegrate::RubyXL
5
+ module AutoSum
6
+ class << self
7
+
8
+ def drop_data
9
+ # since excel layout consistency requires stringified values, we first need
10
+ # to convert strings back to floats.
11
+ try_float_conversion
12
+
13
+ # after the required conversions, drop all values that should not be accepted.
14
+ drop_nil_values
15
+ drop_empty_values
16
+ drop_non_accepted_values
17
+ end
18
+
19
+ def try_float_conversion
20
+ @hash.transform_values! { |array| array.map { |item| item.is_num? ? item.to_f : item } }
21
+ end
22
+
23
+ def drop_nil_values
24
+ @hash.transform_values! &:compact
25
+ end
26
+
27
+ def drop_empty_values
28
+ @hash.transform_values! { |array| array.reject { |item| item.safe_send :empty? } }
29
+ end
30
+
31
+ def drop_non_accepted_values
32
+ @hash.transform_values! { |array| array.reject { |item| !accepted_value? item } }
33
+ end
34
+
35
+ def accepted_value?(value)
36
+ @value = value
37
+ value_is_a_int || value_is_a_float || value_is_a_time_string
38
+ end
39
+
40
+ def value_is_a_int
41
+ @value.is_a? Integer
42
+ end
43
+
44
+ def value_is_a_float
45
+ @value.is_a? Float
46
+ end
47
+
48
+ def value_is_a_time_string
49
+ @value.scan(/\d{2}:\d{2}:\d{2}/).first || @value.scan(/\d{2}:\d{2}/).first
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,27 @@
1
+
2
+ # require "eitil_integrate/application_exporter/auto_sum/format_data"
3
+
4
+ module EitilIntegrate::RubyXL
5
+ module AutoSum
6
+ class << self
7
+
8
+ def format_data
9
+ format_time_strings
10
+ format_ints_to_floats
11
+ end
12
+
13
+ def format_time_strings
14
+ @hash.transform_values! { |array| array.map { |item| incomplete_time_string?(item) ? "#{item}:00" : item } }
15
+ end
16
+
17
+ def incomplete_time_string?(string)
18
+ string.is_a?(String) && string.length == 5 && string.scan(/\d{2}:\d{2}/)
19
+ end
20
+
21
+ def format_ints_to_floats
22
+ @hash.transform_values! { |array| array.map { |item| item.is_a?(Integer) ? item.to_f : item } }
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+
2
+ # require "eitil_integrate/application_exporter/auto_sum/initialize"
3
+
4
+ module EitilIntegrate::RubyXL
5
+ module AutoSum
6
+ class << self
7
+
8
+ def perform(hashed_excel)
9
+ @hash = hashed_excel
10
+
11
+ drop_data
12
+ format_data
13
+ reduce_data
14
+ sum_data
15
+ present_data
16
+
17
+ @hash
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+
2
+ # require "eitil_integrate/application_exporter/auto_sum/present_data"
3
+
4
+ module EitilIntegrate::RubyXL
5
+ module AutoSum
6
+ class << self
7
+
8
+ # As final step, prepare the data for the excel file, according to formatting requirements.
9
+
10
+ def present_data
11
+ transform_floats_to_integers
12
+ transform_values_to_strings
13
+ set_title
14
+ end
15
+
16
+ def transform_floats_to_integers
17
+ @hash.transform_values! { |value| value.is_a?(Float) ? value.safe_to_i.round(3) : value }
18
+ end
19
+
20
+ def transform_values_to_strings
21
+ @hash.transform_values! { |value| value&.to_s }
22
+ end
23
+
24
+ def set_title
25
+ # @hash[0] = 'Totaal' unless @hash[0]
26
+ @hash[0] = 'Totaal'
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,18 @@
1
+
2
+ # require "eitil_integrate/application_exporter/auto_sum/reduce_data"
3
+
4
+ module EitilIntegrate::RubyXL
5
+ module AutoSum
6
+ class << self
7
+
8
+ def reduce_data
9
+ drop_multi_class_arrays
10
+ end
11
+
12
+ def drop_multi_class_arrays
13
+ @hash.transform_values! { |array| array.map(&:class).uniq.length == 1 ? array : [] }
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,56 @@
1
+
2
+ # require "eitil_integrate/application_exporter/auto_sum/sum_data"
3
+
4
+ module EitilIntegrate::RubyXL
5
+ module AutoSum
6
+ class << self
7
+
8
+ # Reduce values and alter data structure.
9
+
10
+ def sum_data
11
+ sum_floats
12
+ sum_time_strings
13
+ unpack_arrays
14
+ end
15
+
16
+ def sum_floats
17
+ @hash.transform_values! { |array| float_array?(array) ? [array.sum] : array }
18
+ end
19
+
20
+ def sum_time_strings
21
+ @hash.transform_values! { |array| time_string_array?(array) ? chronic_sum_array(array) : array }
22
+ end
23
+
24
+ def chronic_sum_array(array)
25
+ sum = array.map { |item| ChronicDuration.parse(item) }.compact.sum
26
+ hours = format_time(sum / (60 * 60))
27
+ sum = sum % (60 * 60)
28
+ minutes = format_time(sum / 60)
29
+ seconds = format_time(sum % 60)
30
+
31
+ # currently doesn't return seconds, since those will never
32
+ # be set (?) and screw the consistency of data formatting
33
+ ["#{hours}:#{minutes}"]
34
+ end
35
+
36
+ def format_time(time)
37
+ time.to_s.length == 1 ? "0#{time}" : time.to_s
38
+ end
39
+
40
+ def float_array?(array)
41
+ return false if array.empty?
42
+ array.all? { |item| item.is_a?(Float) }
43
+ end
44
+
45
+ def time_string_array?(array)
46
+ return false if array.empty?
47
+ array.all? { |item| item.is_a?(String) && item.scan(/\d{2}:\d{2}:\d{2}/) }
48
+ end
49
+
50
+ def unpack_arrays
51
+ @hash.transform_values! { |array| array.empty? ? nil : array.first }
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,43 @@
1
+
2
+ # require "eitil_integrate/application_exporter/default_export"
3
+
4
+ require "eitil_integrate/application_exporter/initialize"
5
+
6
+ module EitilIntegrate::RubyXL
7
+ class ApplicationExporter
8
+
9
+ # The #create_file method is taken out of #export, to be overwritten by
10
+ # exports variants that want to loop over objects and call it multiple times.
11
+ # => e.g. the context of multiple Environment for a single Organisation
12
+
13
+ def export
14
+ prepare_export
15
+ create_file
16
+ process_export
17
+ end
18
+
19
+ private
20
+
21
+ def prepare_export
22
+ validate_args_presence
23
+ validate_args_value
24
+ end
25
+
26
+ def create_file
27
+ name_sheet
28
+ set_data
29
+ validate_data
30
+ fill_messages
31
+ fill_header
32
+ fill_file
33
+ end
34
+
35
+ def process_export
36
+ style_file
37
+ save_file
38
+ end
39
+
40
+ alias_method :base_create_file, :create_file
41
+
42
+ end
43
+ end
@@ -0,0 +1,50 @@
1
+
2
+ # require "eitil_integrate/application_exporter/helpers"
3
+
4
+ require "eitil_integrate/application_exporter/initialize"
5
+
6
+ module EitilIntegrate::RubyXL
7
+ class ApplicationExporter
8
+
9
+ def array_to_indexed_hash(array)
10
+ array = array_nils_substituted(array)
11
+ array = array_values_strf(array)
12
+ array.flatten.map.with_index { |item, index| { "#{index}": item } }.inject &:merge
13
+ end
14
+
15
+ def array_nils_substituted(array)
16
+ array.map { |value| value || '' }
17
+ end
18
+
19
+ def array_values_strf(array)
20
+ array.map &:to_s
21
+ end
22
+
23
+ def sanitize_int(integer)
24
+ (integer.nan? || integer.infinite?) ? 0 : integer
25
+ end
26
+
27
+ def pretty_date_range
28
+ date_range.to_s.gsub '..', ' – '
29
+ end
30
+
31
+ def strf_date_range
32
+ date_range.map &:to_s
33
+ end
34
+
35
+ def double_digit_time(time)
36
+ time.to_s.length == 1 ? "0#{time}" : time.to_s
37
+ end
38
+
39
+ def format_minutes(minutes)
40
+ hours = double_digit_time(minutes / 60)
41
+ minutes = double_digit_time(minutes % 60)
42
+ "#{hours}:#{minutes}"
43
+ end
44
+
45
+ def name_sheet(name='Worksheet')
46
+ sheet.sheet_name = name
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,20 @@
1
+
2
+ # require "eitil_integrate/application_exporter/infos"
3
+
4
+ require "eitil_integrate/application_exporter/initialize"
5
+
6
+ module EitilIntegrate::RubyXL
7
+ class ApplicationExporter
8
+ class << self
9
+
10
+ attr_accessor :info
11
+
12
+ def set_info(_h)
13
+ @info ||= {}
14
+ k, v = *_h.first
15
+ @info[k] = v
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+
2
+ # require "eitil_integrate/application_exporter/initialize"
3
+
4
+ require "eitil_core/setters/set_ivars"
5
+ require "eitil_core/argument_helpers/all_kwargs_to_ivars"
6
+
7
+ # EitilIntegrate::RubyXL::ApplicationExporter
8
+
9
+ module EitilIntegrate
10
+ module RubyXL
11
+ class ApplicationExporter
12
+
13
+ include ActionView::Helpers::NumberHelper
14
+
15
+ attr_accessor :book, :sheet, :x, :y, :start_date, :end_date, :date_range
16
+
17
+ def initialize(attributes={})
18
+ all_kwargs_to_ivars binding, :attributes
19
+ set_ivars :start_date, :end_date, :date_range
20
+ @book = ::RubyXL::Workbook.new
21
+ @sheet = @book.worksheets[0]
22
+ @x ||= 0
23
+ @y ||= 0
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,40 @@
1
+
2
+ # require "eitil_integrate/application_exporter/lookups"
3
+
4
+ require "eitil_integrate/application_exporter/initialize"
5
+ require "eitil_support/directory"
6
+
7
+ module EitilIntegrate::RubyXL
8
+ class ApplicationExporter
9
+
10
+ class << self
11
+
12
+ def exporter_paths
13
+ EitilSupport::Directory.files('app/exporters/exporters').select { |path| path.end_with? '_exporter.rb' }
14
+ end
15
+
16
+ def exporter_names
17
+ exporter_paths.map { |path| path.split('/').last.remove('.rb').camelcase }
18
+ end
19
+
20
+ def exporter_constants
21
+ exporter_names.map &:constantize
22
+ end
23
+
24
+ def exporter_infos
25
+ exporter_constants.map { |_c| { "#{_c}": _c.info || {} } }.inject &:merge
26
+ end
27
+
28
+ alias_method :taxonomy, :exporter_infos
29
+
30
+ def exporter_info(exporter, info)
31
+ exporter_infos[exporter]&.dig(info)
32
+ end
33
+
34
+ def exporter_params
35
+ exporter_infos.transform_values { |v| [v[:required], v[:optional]].flatten.compact }
36
+ end
37
+
38
+ end
39
+ end
40
+ end