hash_dealer 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +3 -1
- data/VERSION +1 -1
- data/hash_dealer.gemspec +2 -2
- data/lib/core_extensions.rb +7 -0
- data/lib/path_string.rb +13 -2
- data/spec/lib/hash_dealer_spec.rb +12 -0
- metadata +3 -3
data/.rspec
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.4
|
data/hash_dealer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{hash_dealer}
|
8
|
-
s.version = "1.3.
|
8
|
+
s.version = "1.3.4"
|
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 = %q{2011-09-
|
12
|
+
s.date = %q{2011-09-08}
|
13
13
|
s.description = %q{Like Factory Girl but for Hashes only}
|
14
14
|
s.email = %q{dan.langevin@lifebooker.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/core_extensions.rb
CHANGED
@@ -11,6 +11,13 @@ class TimeDateMatcher
|
|
11
11
|
@instance = instance
|
12
12
|
end
|
13
13
|
def ==(other)
|
14
|
+
if other.is_a?(String)
|
15
|
+
begin
|
16
|
+
other = self.instance.class.parse(other)
|
17
|
+
rescue => e
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
end
|
14
21
|
self.instance.class == other.class
|
15
22
|
end
|
16
23
|
alias_method :eql?, :==
|
data/lib/path_string.rb
CHANGED
@@ -34,8 +34,10 @@ class PathString < String
|
|
34
34
|
|
35
35
|
# helper method to be called recursively
|
36
36
|
def self.sort_json(val)
|
37
|
-
val
|
38
|
-
val = val
|
37
|
+
return val if val.is_a?(TimeDateMatcher)
|
38
|
+
val = ActiveSupport::JSON.decode(val) if val.is_a?(String)
|
39
|
+
val = self.stringify_keys(val) if val.is_a?(Hash)
|
40
|
+
val = val.collect{|v| v.collect{|n| n.is_a?(Hash) ? self.sort_json(n) : n}} if val.is_a?(Array)
|
39
41
|
val.sort
|
40
42
|
end
|
41
43
|
|
@@ -60,6 +62,15 @@ class PathString < String
|
|
60
62
|
end
|
61
63
|
|
62
64
|
private
|
65
|
+
|
66
|
+
def self.stringify_keys(hash)
|
67
|
+
new_hash = {}
|
68
|
+
hash.each_pair do |k,v|
|
69
|
+
new_hash[k.to_s] = v.is_a?(Hash) ? self.stringify_keys(v) : v
|
70
|
+
end
|
71
|
+
new_hash
|
72
|
+
end
|
73
|
+
|
63
74
|
def self.get_zipped_array(known_path, entered_path)
|
64
75
|
# make these strings
|
65
76
|
known_path, entered_path = known_path.to_s, entered_path.to_s
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'json'
|
1
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
3
|
|
3
4
|
describe HashDealer do
|
@@ -113,6 +114,17 @@ describe HashDealer do
|
|
113
114
|
|
114
115
|
end
|
115
116
|
|
117
|
+
it "should match dates and times from JSON" do
|
118
|
+
HashDealer.define(:var) do
|
119
|
+
id("1")
|
120
|
+
created_at(Time.now)
|
121
|
+
updated_at(Time.now)
|
122
|
+
end
|
123
|
+
|
124
|
+
JSON.unparse({:created_at => Time.now, :updated_at => Time.now, :id => 1}).should match_response(HashDealer.roll(:var).matcher)
|
125
|
+
|
126
|
+
end
|
127
|
+
|
116
128
|
it "should not modify the element when returning a matcher" do
|
117
129
|
HashDealer.define(:array) do
|
118
130
|
my_array([1,2,3])
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: hash_dealer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.3.
|
5
|
+
version: 1.3.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dan Langevin
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-09-
|
13
|
+
date: 2011-09-08 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -141,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
141
|
requirements:
|
142
142
|
- - ">="
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
hash:
|
144
|
+
hash: 284898895399616564
|
145
145
|
segments:
|
146
146
|
- 0
|
147
147
|
version: "0"
|