stockboy 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +5 -0
- data/README.md +19 -0
- data/lib/stockboy/candidate_record.rb +2 -1
- data/lib/stockboy/configuration.rb +8 -0
- data/lib/stockboy/exceptions.rb +17 -0
- data/lib/stockboy/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/stockboy/candidate_record_spec.rb +9 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b590275e79cec3c13367aa9afd5c2834c72136fe
|
4
|
+
data.tar.gz: 5b0c8114e76759d46507f9015a0af11a60dcc322
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebae87b6ddc0f7f90faed9d3e31ea5dc2e381bce97347b16cc94a91386d65e53a7dfa54ae988aeb0721e3f9c81f5a46bc4be676a7e42091b071013e3b0c24266
|
7
|
+
data.tar.gz: b5ee7acaf3385daf91c0dca08c283296a555ba4d37dbdce2a54254a74e2a0398bbc55457f5b3ab138afe6a5a9041985c9ab67ada07ff3a9642a95144343382ef
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
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
|
-
|
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
|
data/lib/stockboy/exceptions.rb
CHANGED
@@ -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
|
data/lib/stockboy/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -57,7 +57,8 @@ module Stockboy
|
|
57
57
|
end
|
58
58
|
|
59
59
|
describe "attribute translation" do
|
60
|
-
|
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.
|
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-
|
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.
|
287
|
+
rubygems_version: 2.5.1
|
288
288
|
signing_key:
|
289
289
|
specification_version: 4
|
290
290
|
summary: Multi-source data normalization library
|