hash_dealer 1.4.7 → 1.4.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/hash_dealer.gemspec +2 -2
- data/lib/comparator.rb +20 -7
- data/lib/core_extensions.rb +6 -1
- metadata +91 -97
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.4.
|
1
|
+
1.4.8
|
data/hash_dealer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "hash_dealer"
|
8
|
-
s.version = "1.4.
|
8
|
+
s.version = "1.4.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dan Langevin"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2012-06-05"
|
13
13
|
s.description = "Like Factory Girl but for Hashes only"
|
14
14
|
s.email = "dan.langevin@lifebooker.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/comparator.rb
CHANGED
@@ -2,11 +2,21 @@ require 'active_support/core_ext'
|
|
2
2
|
|
3
3
|
class Comparator
|
4
4
|
|
5
|
+
def self.formatted_value(val)
|
6
|
+
if val.nil?
|
7
|
+
return "NilClass::nil"
|
8
|
+
elsif val == ""
|
9
|
+
return "''"
|
10
|
+
else
|
11
|
+
return val
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
def self.normalize_value(val)
|
6
16
|
return val if val.is_a?(TimeDateMatcher)
|
7
17
|
val = ActiveSupport::JSON.decode(val) if val.is_a?(String)
|
8
18
|
val = self.stringify_keys(val) if val.is_a?(Hash)
|
9
|
-
val = val.collect{|v| v.is_a?(Hash) ||
|
19
|
+
val = val.collect{|v| v.is_a?(Hash) || v.is_a?(Array) ? self.normalize_value(v) : v} if val.is_a?(Array)
|
10
20
|
val
|
11
21
|
end
|
12
22
|
|
@@ -14,14 +24,17 @@ class Comparator
|
|
14
24
|
return {} if obj1 == obj2
|
15
25
|
return self.array_diff(obj1, obj2) if obj1.is_a?(Array) && obj2.is_a?(Array)
|
16
26
|
return self.hash_diff(obj1, obj2) if obj1.is_a?(Hash) && obj2.is_a?(Hash)
|
17
|
-
return [obj1, obj2
|
27
|
+
return [formatted_value(obj1), "KEY MISSING"] if obj2.nil?
|
28
|
+
return ["KEY MISSING", formatted_value(obj2)] if obj1.nil?
|
29
|
+
return [formatted_value(obj1), formatted_value(obj2)]
|
18
30
|
end
|
19
31
|
|
20
32
|
def self.array_diff(obj1, obj2)
|
21
33
|
{}.tap do |ret|
|
22
|
-
obj1.
|
34
|
+
bigger_arr = obj1.size >= obj2.size ? obj1 : obj2
|
35
|
+
bigger_arr.each_index do |k|
|
23
36
|
ret[k] = self.diff(obj1[k], obj2[k]) unless obj1[k] == obj2[k]
|
24
|
-
end
|
37
|
+
end
|
25
38
|
end
|
26
39
|
end
|
27
40
|
|
@@ -29,9 +42,9 @@ class Comparator
|
|
29
42
|
obj1, obj2 = self.stringify_keys(obj1), self.stringify_keys(obj2)
|
30
43
|
(obj1.keys + obj2.keys).uniq.inject({}) do |memo, key|
|
31
44
|
if !obj1.keys.include?(key)
|
32
|
-
memo[key] = ["KEY MISSING", obj2[key]]
|
45
|
+
memo[key] = ["KEY MISSING", formatted_value(obj2[key])]
|
33
46
|
elsif !obj2.keys.include?(key)
|
34
|
-
memo[key] = [obj1[key], "KEY MISSING"]
|
47
|
+
memo[key] = [formatted_value(obj1[key]), "KEY MISSING"]
|
35
48
|
elsif obj1[key] != obj2[key]
|
36
49
|
memo[key] = self.diff(obj1[key], obj2[key])
|
37
50
|
end
|
@@ -47,4 +60,4 @@ class Comparator
|
|
47
60
|
end
|
48
61
|
end
|
49
62
|
end
|
50
|
-
end
|
63
|
+
end
|
data/lib/core_extensions.rb
CHANGED
@@ -136,7 +136,12 @@ class Hash
|
|
136
136
|
if opts[:only].include?(k.to_sym)
|
137
137
|
ret[k] = v.matcher(opts[k.to_sym] || {})
|
138
138
|
else
|
139
|
-
|
139
|
+
# Still try to pathify strings if this is an array or hash
|
140
|
+
if v.is_a?(Array) || v.is_a?(Hash)
|
141
|
+
ret[k] = v.pathify_strings
|
142
|
+
else
|
143
|
+
ret[k] = v
|
144
|
+
end
|
140
145
|
end
|
141
146
|
end
|
142
147
|
ret
|
metadata
CHANGED
@@ -1,137 +1,134 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_dealer
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.4.8
|
4
5
|
prerelease:
|
5
|
-
version: 1.4.7
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Dan Langevin
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-06-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: activesupport
|
17
|
-
requirement: &
|
16
|
+
requirement: &2152723880 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
26
|
-
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: *2152723880
|
25
|
+
- !ruby/object:Gem::Dependency
|
27
26
|
name: i18n
|
28
|
-
requirement: &
|
27
|
+
requirement: &2152723300 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
|
-
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
37
|
-
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: *2152723300
|
36
|
+
- !ruby/object:Gem::Dependency
|
38
37
|
name: colorize
|
39
|
-
requirement: &
|
38
|
+
requirement: &2152722740 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version:
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
45
44
|
type: :runtime
|
46
45
|
prerelease: false
|
47
|
-
version_requirements: *
|
48
|
-
- !ruby/object:Gem::Dependency
|
46
|
+
version_requirements: *2152722740
|
47
|
+
- !ruby/object:Gem::Dependency
|
49
48
|
name: bundler
|
50
|
-
requirement: &
|
49
|
+
requirement: &2152716020 !ruby/object:Gem::Requirement
|
51
50
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version:
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
56
55
|
type: :development
|
57
56
|
prerelease: false
|
58
|
-
version_requirements: *
|
59
|
-
- !ruby/object:Gem::Dependency
|
57
|
+
version_requirements: *2152716020
|
58
|
+
- !ruby/object:Gem::Dependency
|
60
59
|
name: jeweler
|
61
|
-
requirement: &
|
60
|
+
requirement: &2152715420 !ruby/object:Gem::Requirement
|
62
61
|
none: false
|
63
|
-
requirements:
|
64
|
-
- -
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version:
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
67
66
|
type: :development
|
68
67
|
prerelease: false
|
69
|
-
version_requirements: *
|
70
|
-
- !ruby/object:Gem::Dependency
|
68
|
+
version_requirements: *2152715420
|
69
|
+
- !ruby/object:Gem::Dependency
|
71
70
|
name: rspec
|
72
|
-
requirement: &
|
71
|
+
requirement: &2152714880 !ruby/object:Gem::Requirement
|
73
72
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version:
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
78
77
|
type: :development
|
79
78
|
prerelease: false
|
80
|
-
version_requirements: *
|
81
|
-
- !ruby/object:Gem::Dependency
|
79
|
+
version_requirements: *2152714880
|
80
|
+
- !ruby/object:Gem::Dependency
|
82
81
|
name: rcov
|
83
|
-
requirement: &
|
82
|
+
requirement: &2152714220 !ruby/object:Gem::Requirement
|
84
83
|
none: false
|
85
|
-
requirements:
|
86
|
-
- -
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version:
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
89
88
|
type: :development
|
90
89
|
prerelease: false
|
91
|
-
version_requirements: *
|
92
|
-
- !ruby/object:Gem::Dependency
|
90
|
+
version_requirements: *2152714220
|
91
|
+
- !ruby/object:Gem::Dependency
|
93
92
|
name: guard-rspec
|
94
|
-
requirement: &
|
93
|
+
requirement: &2152713380 !ruby/object:Gem::Requirement
|
95
94
|
none: false
|
96
|
-
requirements:
|
97
|
-
- -
|
98
|
-
- !ruby/object:Gem::Version
|
95
|
+
requirements:
|
96
|
+
- - =
|
97
|
+
- !ruby/object:Gem::Version
|
99
98
|
version: 0.4.0
|
100
99
|
type: :development
|
101
100
|
prerelease: false
|
102
|
-
version_requirements: *
|
103
|
-
- !ruby/object:Gem::Dependency
|
101
|
+
version_requirements: *2152713380
|
102
|
+
- !ruby/object:Gem::Dependency
|
104
103
|
name: ruby-debug19
|
105
|
-
requirement: &
|
104
|
+
requirement: &2152712340 !ruby/object:Gem::Requirement
|
106
105
|
none: false
|
107
|
-
requirements:
|
108
|
-
- -
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version:
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
111
110
|
type: :development
|
112
111
|
prerelease: false
|
113
|
-
version_requirements: *
|
114
|
-
- !ruby/object:Gem::Dependency
|
112
|
+
version_requirements: *2152712340
|
113
|
+
- !ruby/object:Gem::Dependency
|
115
114
|
name: simplecov
|
116
|
-
requirement: &
|
115
|
+
requirement: &2152710780 !ruby/object:Gem::Requirement
|
117
116
|
none: false
|
118
|
-
requirements:
|
119
|
-
- -
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
version:
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
122
121
|
type: :development
|
123
122
|
prerelease: false
|
124
|
-
version_requirements: *
|
123
|
+
version_requirements: *2152710780
|
125
124
|
description: Like Factory Girl but for Hashes only
|
126
125
|
email: dan.langevin@lifebooker.com
|
127
126
|
executables: []
|
128
|
-
|
129
127
|
extensions: []
|
130
|
-
|
131
|
-
extra_rdoc_files:
|
128
|
+
extra_rdoc_files:
|
132
129
|
- LICENSE.txt
|
133
130
|
- README.rdoc
|
134
|
-
files:
|
131
|
+
files:
|
135
132
|
- .document
|
136
133
|
- .rspec
|
137
134
|
- Gemfile
|
@@ -153,34 +150,31 @@ files:
|
|
153
150
|
- spec/lib/path_string_spec.rb
|
154
151
|
- spec/spec_helper.rb
|
155
152
|
homepage: http://github.com/LifebookerInc/hash_dealer
|
156
|
-
licenses:
|
153
|
+
licenses:
|
157
154
|
- MIT
|
158
155
|
post_install_message:
|
159
156
|
rdoc_options: []
|
160
|
-
|
161
|
-
require_paths:
|
157
|
+
require_paths:
|
162
158
|
- lib
|
163
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
160
|
none: false
|
165
|
-
requirements:
|
166
|
-
- -
|
167
|
-
- !ruby/object:Gem::Version
|
168
|
-
|
169
|
-
segments:
|
161
|
+
requirements:
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
segments:
|
170
166
|
- 0
|
171
|
-
|
172
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
hash: 195646365187188942
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
169
|
none: false
|
174
|
-
requirements:
|
175
|
-
- -
|
176
|
-
- !ruby/object:Gem::Version
|
177
|
-
version:
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
178
174
|
requirements: []
|
179
|
-
|
180
175
|
rubyforge_project:
|
181
176
|
rubygems_version: 1.8.11
|
182
177
|
signing_key:
|
183
178
|
specification_version: 3
|
184
179
|
summary: Hash Factory - like Factory Girl but for Hashes only
|
185
180
|
test_files: []
|
186
|
-
|