dynport_tools 0.2.13 → 0.2.14

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.13
1
+ 0.2.14
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dynport_tools}
8
- s.version = "0.2.13"
8
+ s.version = "0.2.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tobias Schwab"]
12
- s.date = %q{2011-08-25}
12
+ s.date = %q{2011-09-02}
13
13
  s.description = %q{Collection of various tools}
14
14
  s.email = %q{tobias.schwab@dynport.de}
15
15
  s.executables = ["xmldiff", "redis_dumper"]
@@ -85,15 +85,21 @@ module DynportTools
85
85
  def all_array_indexes(a, b)
86
86
  0.upto([a.length, b.length].max - 1).to_a
87
87
  end
88
+
89
+ def hash_value_from_key(hash, key, symbolize = false)
90
+ if !symbolize || hash.has_key?(key)
91
+ hash[key]
92
+ elsif key.is_a?(Symbol)
93
+ hash[key.to_s]
94
+ else
95
+ hash[key.to_sym]
96
+ end
97
+ end
88
98
 
89
99
  def diff_hash_values(a, b, keys)
90
100
  ret = keys.uniq.inject({}) do |hash, key|
91
- value_a = a[key]
92
- value_b = b[key]
93
- if symbolize_keys
94
- value_a ||= a[key.is_a?(Symbol) ? key.to_s : key.to_sym]
95
- value_b ||= b[key.is_a?(Symbol) ? key.to_s : key.to_sym]
96
- end
101
+ value_a = hash_value_from_key(a, key, symbolize_keys)
102
+ value_b = hash_value_from_key(b, key, symbolize_keys)
97
103
  if diff = diff(value_a, value_b)
98
104
  hash[key] = diff
99
105
  end
@@ -37,6 +37,13 @@ class DynportTools::ETA
37
37
  current / running_for
38
38
  end
39
39
 
40
+ def seconds_to_time(time)
41
+ hours = time / 3600.0
42
+ minutes = time / 60.0
43
+ seconds = time
44
+ "%02d:%02d:%02d" % [hours.floor, (minutes.floor % 3600) % 60, seconds.floor % 60]
45
+ end
46
+
40
47
  def to_s
41
48
  "%.2f%%, %.2f/second, ETA: %s" % [percs * 100, per_second, eta.iso8601]
42
49
  end
@@ -35,6 +35,12 @@ describe DynportTools::Differ do
35
35
  b = %(-e production 'something)
36
36
  uncolor(differ.diff_strings(a, b)).should == %(-e production<_slave|> <"|'>something)
37
37
  end
38
+
39
+ it "diffs an edge case correctly" do
40
+ a = "#!/bin/sh\nssh s7 \"cd /opt/simfy/app/simfy_production/current && ./script/runner -e production \\\"Importer.import_catalog('kontor')\\\"\""
41
+ b = "cd /opt/simfy/app/simfy_production/current && ./script/runner -e production \"Importer.import_catalog('kontor')\""
42
+ pending "fix me"
43
+ end
38
44
  end
39
45
 
40
46
  describe "diffing two hashes" do
@@ -43,6 +49,11 @@ describe DynportTools::Differ do
43
49
  differ.diff(hash, hash).should be_nil
44
50
  end
45
51
 
52
+ it "works with nil and false values when using symbolize_keys" do
53
+ differ.symbolize_keys = true
54
+ differ.diff({"test" => false}, { :test => false}).should be_nil
55
+ end
56
+
46
57
  it "returns true when symbolize_keys is set to true and comparing hashes with symbols and strings" do
47
58
  differ.symbolize_keys = true
48
59
  differ.diff({ :a => 1 }, { "a" => 1 }).should be_nil
@@ -37,6 +37,8 @@ describe "DynportTools::ETA" do
37
37
  "00:15:26" => 926,
38
38
  "00:00:26" => 26,
39
39
  "1:00:26" => 3626,
40
+ "10.0" => 10,
41
+ "9000.0" => 9000
40
42
  }.each do |from, to|
41
43
  it "returns #{to} for #{from}" do
42
44
  DynportTools::ETA.parse_time_string(from).should == to
@@ -103,6 +105,14 @@ describe "DynportTools::ETA" do
103
105
  DynportTools::ETA.new(:current => 10, :total => 100, :started => time - 1).to_s.should == "10.00%, 10.00/second, ETA: 2011-02-03T04:50:09+01:00"
104
106
  end
105
107
 
108
+ describe "#seconds_to_human" do
109
+ { 1 => "00:00:01", 61 => "00:01:01", 3661 => "01:01:01" }.each do |from, to|
110
+ it "retrurns #{to} for #{from}" do
111
+ DynportTools::ETA.new.seconds_to_time(from).should == to
112
+ end
113
+ end
114
+ end
115
+
106
116
  describe "#from_time_string" do
107
117
  it "sets the correct values" do
108
118
  eta = DynportTools::ETA.from_time_string("00:01:10", :total => 100)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynport_tools
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 13
10
- version: 0.2.13
9
+ - 14
10
+ version: 0.2.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tobias Schwab
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-25 00:00:00 +02:00
18
+ date: 2011-09-02 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency