ntq_excelsior 1.4.0 → 1.4.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: b6a5e24a80fa3a23cb825780ed3d507a35fd431c17fc6bf0cebef21136bd76b4
4
- data.tar.gz: 1a82ce13bfcb6fa6cee43183506c971f5f5c603dc2c7889c4c9cec75de87f584
3
+ metadata.gz: c2860934f0b20b6d7daf121020a2c297c3e56586428bd28656340af0e42bab96
4
+ data.tar.gz: 14b94f8385b15e3812a9c40daa7e8a8116c35a9e1cf6a8accf85887f3ce876bb
5
5
  SHA512:
6
- metadata.gz: fc0f3a348f3287e7853f7dd5e95a50ec36814b99a51b32a2e296a086512e69ac09febc3e6ce0eaf1ba25c910b498e65d09693b1bca8c5ae7cf66c551d6d3cc72
7
- data.tar.gz: '0481f21e47076aba37d617814989d18735977edf0d78f74542b1791ab6a91a09ae891c4695a38e516c97692b737a39ac085c270cced400c5af2324f82a14dbb5'
6
+ metadata.gz: d5f7d219d75ded2020a1e92eeeb84536653e8f7ab419d91698c64acdf9809fbfbdd75e5f00c8db493eb8129c296341bab7885a71f1f8c34abb0fcb0485fd2061
7
+ data.tar.gz: 92061140c2a2f9b0072c39376ce1eec4cafcd3939df55e41db785b80262343c96406fd11d6bf0311c5f2fe05d5d03b56897754962e6d65caec2497d517ac8f50
@@ -0,0 +1,15 @@
1
+ require 'ostruct'
2
+
3
+ module NtqExcelsior
4
+ class Context < OpenStruct
5
+ attr_accessor :success
6
+
7
+ def success?
8
+ @success.nil? || @success
9
+ end
10
+
11
+ def error?
12
+ !@success.nil? && !@success
13
+ end
14
+ end
15
+ end
@@ -1,8 +1,10 @@
1
1
  require 'roo'
2
+ require 'ntq_excelsior/context'
2
3
 
3
4
  module NtqExcelsior
4
5
  class Importer
5
- attr_accessor :file, :check, :lines, :options, :status_tracker
6
+ attr_accessor :file, :check, :lines, :options, :status_tracker, :success
7
+ attr_reader :context
6
8
 
7
9
  class << self
8
10
  def autosave(value = nil)
@@ -29,6 +31,16 @@ module NtqExcelsior
29
31
  @schema ||= value
30
32
  end
31
33
 
34
+ def before(&block)
35
+ @before = block if block_given?
36
+ @before
37
+ end
38
+
39
+ def after(&block)
40
+ @after = block if block_given?
41
+ @after
42
+ end
43
+
32
44
  def max_error_count(value = nil)
33
45
  @max_error_count ||= value
34
46
  end
@@ -42,6 +54,10 @@ module NtqExcelsior
42
54
  end
43
55
  end
44
56
 
57
+ def initialize
58
+ @context = NtqExcelsior::Context.new
59
+ end
60
+
45
61
  def spreadsheet
46
62
  return @spreadsheet unless @spreadsheet.nil?
47
63
 
@@ -134,7 +150,7 @@ module NtqExcelsior
134
150
  def lines
135
151
  return @lines if @lines
136
152
 
137
- @lines = spreadsheet_data.map {|line| parse_line(line) }
153
+ @lines = spreadsheet_data.map { |line| parse_line(line) }
138
154
  end
139
155
 
140
156
  # id for default query in model
@@ -197,6 +213,7 @@ module NtqExcelsior
197
213
  end
198
214
 
199
215
  def import(save: true, status_tracker: nil)
216
+ self.class.before.call(@context, options) if self.class.before.is_a?(Proc)
200
217
  at = 0
201
218
  errors_lines = []
202
219
  success_count = 0
@@ -222,7 +239,10 @@ module NtqExcelsior
222
239
  end
223
240
  end
224
241
 
225
- { success_count: success_count, not_found_count: not_found_count, errors: errors_lines }
242
+ import_stats = { success_count: success_count, not_found_count: not_found_count, errors: errors_lines }
243
+ @context.success = true if errors_lines.empty?
244
+ self.class.after.call(@context, options) if self.class.after.is_a?(Proc)
245
+ import_stats
226
246
  end
227
247
 
228
248
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NtqExcelsior
4
- VERSION = "1.4.0"
5
- end
4
+ VERSION = "1.4.1"
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ntq_excelsior
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-24 00:00:00.000000000 Z
11
+ date: 2024-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: caxlsx
@@ -56,6 +56,7 @@ files:
56
56
  - README.md
57
57
  - Rakefile
58
58
  - lib/ntq_excelsior.rb
59
+ - lib/ntq_excelsior/context.rb
59
60
  - lib/ntq_excelsior/exporter.rb
60
61
  - lib/ntq_excelsior/importer.rb
61
62
  - lib/ntq_excelsior/multi_workbook_exporter.rb