bespoke 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ require "bespoke/exportable"
5
5
  class Bespoke
6
6
  attr_reader :collection, :exports
7
7
 
8
- def initialize(hash)
8
+ def initialize(hash, logger=nil)
9
9
  @collection = IndexedCollection.new
10
10
  hash["index"].each_pair do |name, column|
11
11
  @collection.index name, column
@@ -15,7 +15,7 @@ class Bespoke
15
15
  outputs = @exports[output_name] = []
16
16
  exportable_configs.each do |config|
17
17
  config.each_pair do |collection_name, attrs|
18
- outputs << (export = Exportable.new(collection_name))
18
+ outputs << (export = Exportable.new(collection_name, logger))
19
19
  (attrs["fields"] || {}).each_pair do |field, template|
20
20
  export.field field, template
21
21
  end
@@ -1,19 +1,20 @@
1
1
  require 'csv'
2
2
  require 'docile'
3
3
  require 'mustache'
4
+ require 'logger'
4
5
 
5
6
  class Bespoke
6
7
  class Error < StandardError; end
7
8
  MissingTable = Class.new(Error)
8
- MissingJoin = Class.new(Error)
9
9
 
10
10
  class Exportable
11
11
  attr_accessor :name, :fields, :joins
12
12
 
13
- def initialize(name)
13
+ def initialize(name, logger=nil)
14
14
  @name = name.to_sym
15
15
  @fields = {}
16
16
  @joins = {}
17
+ @logger = logger || Logger.new(STDERR)
17
18
  end
18
19
 
19
20
  def headers
@@ -37,7 +38,7 @@ class Bespoke
37
38
  if other_table.has_key?(row[key])
38
39
  context[join_name.to_sym] = other_table[row[key]]
39
40
  else
40
- raise MissingJoin, "Expected foreign key #{key} with value #{row[key]} in table #{join_name}"
41
+ @logger.warn "Expected foreign key #{key} with value #{row[key]} in table #{join_name} (#{row.inspect})"
41
42
  end
42
43
  else
43
44
  raise MissingTable, "Expected #{join_name}"
@@ -1,3 +1,3 @@
1
1
  class Bespoke
2
- VERSION = '0.1.0' unless defined?(Bespoke::VERSION)
2
+ VERSION = '0.1.1' unless defined?(Bespoke::VERSION)
3
3
  end
@@ -1,10 +1,13 @@
1
1
  require_relative 'spec_helper'
2
+ require 'logger'
3
+ require 'stringio'
2
4
 
3
5
  describe Bespoke::Exportable do
4
- let(:export) { Bespoke::Exportable.new(:test) }
6
+ let(:logger) { nil }
7
+ let(:export) { Bespoke::Exportable.new(:test, logger) }
5
8
 
6
9
  it "initializes" do
7
- Bespoke::Exportable.new(:test)
10
+ export
8
11
  end
9
12
 
10
13
  it "exports templated rows" do
@@ -15,4 +18,26 @@ describe Bespoke::Exportable do
15
18
  }})
16
19
  data.should == [["1-2"], ["5-10"]]
17
20
  end
21
+
22
+ context "logging" do
23
+ let(:output) { StringIO.new }
24
+ let(:logger) { Logger.new(output) }
25
+
26
+ it "logs missing join data" do
27
+ export.field(:column, "{{test.id}}-{{test.value}}")
28
+ export.join(:user, :id)
29
+ data = export.export({
30
+ :user => {
31
+ 1 => {:test_id => 1, :name => "Duane"},
32
+ 2 => {:test_id => 2, :name => "Ken"},
33
+ },
34
+ :test => {
35
+ 1 => {:id => 1, :value => 2},
36
+ 2 => {:id => 5, :value => 10}
37
+ }
38
+ })
39
+ log_msg = output.string.split(' : ')[1]
40
+ log_msg.should == "Expected foreign key id with value 5 in table user ({:id=>5, :value=>10})\n"
41
+ end
42
+ end
18
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bespoke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-31 00:00:00.000000000 Z
12
+ date: 2014-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler