yaml_db_anonymizer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,7 +36,11 @@ module YamlDb
36
36
  def anonymize(table, column, value)
37
37
  return value unless self.definition.key?(table.to_s) and self.definition[table.to_s].key?(column.to_s)
38
38
  block_or_value = self.definition[table.to_s][column.to_s]
39
- block_or_value.is_a?(Proc) ? block_or_value.call(value) : block_or_value
39
+ if block_or_value.is_a?(Proc)
40
+ block_or_value.arity == 1 ? block_or_value.call(value) : block_or_value.call
41
+ else
42
+ block_or_value
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -3,7 +3,9 @@ module YamlDb
3
3
  class Dump < ::YamlDb::Dump
4
4
 
5
5
  def self.dump_table_records(io, table)
6
+ return super(io, table) unless Anonymizer.definition.is_a? Hash
6
7
  return if Anonymizer.definition[table.to_s] == :truncate
8
+
7
9
  table_record_header(io)
8
10
 
9
11
  column_names = table_column_names(table)
@@ -23,7 +25,7 @@ module YamlDb
23
25
  end
24
26
 
25
27
  def self.dump_table_columns(io, table)
26
- super(io, table) unless Anonymizer.definition[table.to_s] == :truncate
28
+ super(io, table) unless Anonymizer.definition.is_a?(Hash) && Anonymizer.definition[table.to_s] == :truncate
27
29
  end
28
30
 
29
31
  end
@@ -1,5 +1,5 @@
1
1
  module YamlDb
2
2
  module Anonymizer
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -8,6 +8,7 @@ describe YamlDb::Anonymizer do
8
8
  remove :a
9
9
  replace :b, with: 0
10
10
  replace :c, with: lambda { |val| "Anonymized #{val}" }
11
+ replace :d, with: lambda { "Anonymized value" }
11
12
  end
12
13
  end
13
14
  end
@@ -23,6 +24,10 @@ describe YamlDb::Anonymizer do
23
24
  it "should anonymize with blocks" do
24
25
  YamlDb::Anonymizer.anonymize(:mytable, :c, "bar").should == "Anonymized bar"
25
26
  end
27
+
28
+ it "should anonymize with blocks" do
29
+ YamlDb::Anonymizer.anonymize(:mytable, :d, "bar").should == "Anonymized value"
30
+ end
26
31
  end
27
32
 
28
33
  context 'export' do
@@ -87,5 +92,24 @@ EOYAML
87
92
  end
88
93
  end
89
94
  end
95
+
96
+ context 'fallback' do
97
+ let(:io) { double('io') }
98
+ let(:table) { double('table') }
99
+
100
+ before do
101
+ YamlDb::Anonymizer.definition = nil
102
+ end
103
+
104
+ it 'falls back to YamlDb::Dump.dump_table_records if definition is missing' do
105
+ YamlDb::Dump.should_receive(:dump_table_records).with(io, table)
106
+ YamlDb::Anonymizer::Dump.dump_table_records(io, table)
107
+ end
108
+
109
+ it 'falls back to YamlDb::Dump.dump_table_columns if definition is missing' do
110
+ YamlDb::Dump.should_receive(:dump_table_columns).with(io, table)
111
+ YamlDb::Anonymizer::Dump.dump_table_columns(io, table)
112
+ end
113
+ end
90
114
  end
91
115
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml_db_anonymizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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: 2012-08-23 00:00:00.000000000 Z
12
+ date: 2012-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yaml_db