stockboy 1.1.2 → 1.2.0

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
  SHA1:
3
- metadata.gz: b61bae292712fd23cbd3670b7af75f1c1accd9f3
4
- data.tar.gz: b7bf75470c330236ae3853f3a70a73827197da2b
3
+ metadata.gz: b590275e79cec3c13367aa9afd5c2834c72136fe
4
+ data.tar.gz: 5b0c8114e76759d46507f9015a0af11a60dcc322
5
5
  SHA512:
6
- metadata.gz: debeaaa64a47c5ebd9cf4feeff2f2e4d7410eb59c4157d4ddadf8b498a807bc84558db597d7e4d3bd72b9bee0c599181e8ebac9370e9e48fb13f0cbd066d0966
7
- data.tar.gz: f1474b711a72cbda96c44e3324d0214c8a2270ba4c0d81529ebb07d8a848a580e74c260ae01679de4b8dfc7cb99209cd33f0186501f23752ea19562794c15af7
6
+ metadata.gz: ebae87b6ddc0f7f90faed9d3e31ea5dc2e381bce97347b16cc94a91386d65e53a7dfa54ae988aeb0721e3f9c81f5a46bc4be676a7e42091b071013e3b0c24266
7
+ data.tar.gz: b5ee7acaf3385daf91c0dca08c283296a555ba4d37dbdce2a54254a74e2a0398bbc55457f5b3ab138afe6a5a9041985c9ab67ada07ff3a9642a95144343382ef
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0 / 2016-08-02
4
+
5
+ * [ENHANCEMENT] Option to handle errors raised in translation chain
6
+
3
7
  ## 1.1.2 / 2016-05-26
4
8
 
5
9
  * [BUGFIX] Cast other types in string converter to string
data/Gemfile CHANGED
@@ -22,3 +22,8 @@ platforms :rbx do
22
22
  gem "rubysl", "~> 2.0"
23
23
  gem "racc"
24
24
  end
25
+
26
+ if RUBY_VERSION < "2.2.2"
27
+ gem "rack", '<2.0'
28
+ gem "activesupport", "<5.0"
29
+ end
data/README.md CHANGED
@@ -261,6 +261,25 @@ individually as `attribute :name`.
261
261
  [ukda]: lib/stockboy/translators/uk_date.rb
262
262
  [usda]: lib/stockboy/translators/us_date.rb
263
263
 
264
+ #### Debugging attribute translations
265
+
266
+ If an attribute can't be translated the default behaviour is to return `nil`
267
+ instead of raising an error that would terminate the entire job. There is a
268
+ global config option to handle these errors as needed, perhaps for debugging:
269
+
270
+ Stockboy.configuration.translation_error_handler = proc { |error|
271
+ puts "Failed attribute: #{error.key.inspect}"
272
+ puts "Input: #{error.record.raw_hash.inspect}"
273
+ puts error.backtrace
274
+ }
275
+
276
+ The object yielded to the error handler is an exception with additional properties:
277
+
278
+ * `key`: The name of the attribute key that was attempted to translate
279
+ * `record`: The original record context with all the input fields for inspection
280
+
281
+ It can simply be raised if preferred.
282
+
264
283
 
265
284
  ### 4. Funnel it with filters
266
285
 
@@ -119,7 +119,8 @@ module Stockboy
119
119
  fields[key] = tr[value]
120
120
  SourceRecord.new(fields, @table)
121
121
  rescue
122
- fields[key] = nil
122
+ translation_error = TranslationError.new(key, self)
123
+ fields[key] = Stockboy.configuration.translation_error_handler.call(translation_error)
123
124
  break SourceRecord.new(fields, @table)
124
125
  end
125
126
  end
@@ -27,6 +27,13 @@ module Stockboy
27
27
  #
28
28
  attr_accessor :logger
29
29
 
30
+ # To allow inspection when tranlastion error occurs
31
+ #
32
+ # By default returns nil on error but can be overridden
33
+ attr_accessor :translation_error_handler
34
+
35
+
36
+
30
37
  # Initialize a set of global configuration options
31
38
  #
32
39
  # @yield self for configuration
@@ -35,6 +42,7 @@ module Stockboy
35
42
  @template_load_paths = []
36
43
  @logger = Logger.new(STDOUT)
37
44
  @tmp_dir = Dir.tmpdir
45
+ @translation_error_handler = -> (error) { nil }
38
46
  yield self if block_given?
39
47
  end
40
48
  end
@@ -1,3 +1,20 @@
1
1
  module Stockboy
2
2
  class OutOfSequence < StandardError; end
3
+
4
+ # TranslationError is a wrapper to store the standard error as well as the key and record which caused it
5
+ class TranslationError < StandardError
6
+
7
+ def initialize (key, record)
8
+ @key = key
9
+ @record = record
10
+ end
11
+
12
+ def message
13
+ "Attribute [#{key}] caused #{cause.message}"
14
+ end
15
+
16
+ attr_reader :key
17
+ attr_reader :record
18
+
19
+ end
3
20
  end
@@ -1,3 +1,3 @@
1
1
  module Stockboy
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -21,6 +21,7 @@ require 'rspec/its'
21
21
  require 'ostruct'
22
22
  require 'savon'
23
23
  require 'savon/mock/spec_helper'
24
+ require 'pathname'
24
25
  # require 'vcr'
25
26
 
26
27
  $:.unshift File.expand_path('../lib/stockboy/lib', __FILE__)
@@ -57,7 +57,8 @@ module Stockboy
57
57
  end
58
58
 
59
59
  describe "attribute translation" do
60
- subject(:hash) { CandidateRecord.new(hash_attrs, map).to_hash }
60
+ let (:record) { CandidateRecord.new(hash_attrs, map) }
61
+ subject(:hash) { record.to_hash }
61
62
 
62
63
  context "from lambda" do
63
64
  let(:map) { AttributeMap.new{ birthday as: ->(r){ Date.parse(r.birthday) } } }
@@ -78,6 +79,13 @@ module Stockboy
78
79
  context "with exception" do
79
80
  let(:map) { AttributeMap.new{ id as: [->(r){r.id.to_i}, ->(r){r.id / 0}] } }
80
81
  it { should eq({id: nil}) }
82
+
83
+ context "while debugging" do
84
+ it "raises the error" do
85
+ Stockboy.configuration.translation_error_handler = -> (error) { raise error }
86
+ expect { hash }.to(raise_error(Stockboy::TranslationError))
87
+ end
88
+ end
81
89
  end
82
90
 
83
91
  context "dynamic without an input field" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stockboy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Vit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-26 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -284,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
284
284
  version: '0'
285
285
  requirements: []
286
286
  rubyforge_project: stockboy
287
- rubygems_version: 2.2.2
287
+ rubygems_version: 2.5.1
288
288
  signing_key:
289
289
  specification_version: 4
290
290
  summary: Multi-source data normalization library