hash_dealer 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.3
1
+ 1.2.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.2.3"
8
+ s.version = "1.2.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-08-23}
12
+ s.date = %q{2011-08-24}
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 = [
@@ -5,6 +5,17 @@ class Object
5
5
  end
6
6
  end
7
7
 
8
+ class Numeric
9
+ def matcher(opts={})
10
+ PathString.new(":#{self}")
11
+ end
12
+ def ==(other)
13
+ return true if other.is_a?(PathString) && other =~ /^:/
14
+ super
15
+ end
16
+ alias_method :eql?, :==
17
+ end
18
+
8
19
  # The only really important matcher
9
20
  class String
10
21
  def matcher(opts = {})
@@ -18,8 +29,8 @@ class Hash
18
29
  self.each_pair do |k,v|
19
30
  if v.is_a?(Array) || v.is_a?(Hash)
20
31
  v.pathify_strings!
21
- elsif v.instance_of?(String)
22
- self[k] = PathString.new(URI.decode(v))
32
+ elsif v.instance_of?(String) || v.is_a?(Numeric)
33
+ self[k] = PathString.new(URI.decode(v.to_s))
23
34
  end
24
35
  end
25
36
  end
@@ -45,8 +56,8 @@ class Array
45
56
  self.each_with_index do |v,k|
46
57
  if v.is_a?(Array) || v.is_a?(Hash)
47
58
  v.pathify_strings!
48
- elsif v.instance_of?(String)
49
- self[k] = PathString.new(URI.decode(v))
59
+ elsif v.instance_of?(String) || v.is_a?(Numeric)
60
+ self[k] = PathString.new(URI.decode(v.to_s))
50
61
  end
51
62
  end
52
63
  end
data/lib/path_string.rb CHANGED
@@ -4,7 +4,7 @@ class PathString < String
4
4
 
5
5
  def == (other)
6
6
  # if either is a string that starts with a :, return true
7
- if self =~ /^:/ || other =~ /^:/
7
+ if self =~ /^:/ || (other.is_a?(Numeric) && self =~ /^:\d+$/) || other =~ /^:/
8
8
  return true
9
9
  elsif self =~ /\/:/ || other =~ /\/:/
10
10
  return self.class.paths_match?(self, other)
@@ -12,6 +12,7 @@ class PathString < String
12
12
  super
13
13
  end
14
14
  end
15
+ alias_method :eql?, :==
15
16
 
16
17
  def self.paths_match?(a, b)
17
18
  self.get_zipped_array(a, b).each do |kp, ep|
@@ -26,11 +27,18 @@ class PathString < String
26
27
  end
27
28
 
28
29
  def self.as_sorted_json(val)
29
- val = val.is_a?(String) ? ActiveSupport::JSON.decode(val).sort : ActiveSupport::JSON.decode(ActiveSupport::JSON.encode(val)).sort
30
+ val = self.sort_json(val)
30
31
  val.pathify_strings!
31
32
  val
32
33
  end
33
34
 
35
+ # helper method to be called recursively
36
+ def self.sort_json(val)
37
+ val = val.is_a?(String) ? ActiveSupport::JSON.decode(val).sort : ActiveSupport::JSON.decode(ActiveSupport::JSON.encode(val)).sort
38
+ val = val.collect{|v| v.collect{|n| n.is_a?(Hash) ? self.sort_json(n) : n}}
39
+ val
40
+ end
41
+
34
42
  #
35
43
  #
36
44
  def self.extract_params(known_path, entered_path)
@@ -94,6 +94,14 @@ describe HashDealer do
94
94
  HashDealer.roll(:parent).matcher(:only => [:b], :b => {:except => [:a]})[:b][:b].should eql(":child_b")
95
95
  end
96
96
 
97
+ it "should match on numeric values" do
98
+ HashDealer.define(:parent) do
99
+ a(1)
100
+ end
101
+ HashDealer.roll(:parent).matcher[:a].should eql 100
102
+ HashDealer.roll(:parent)[:a].should_not eql 100
103
+ end
104
+
97
105
  it "should define a matcher for when the response is an Array" do
98
106
  HashDealer.define(:variable) do
99
107
  root([{
@@ -36,5 +36,4 @@ describe PathString do
36
36
  it "should match wildcard paths" do
37
37
  PathString.paths_match?("/a/1/test/2", "/a/:1/test/:2").should be_true
38
38
  end
39
-
40
39
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hash_dealer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.3
5
+ version: 1.2.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-08-23 00:00:00 Z
13
+ date: 2011-08-24 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -129,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
129
  requirements:
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
- hash: -4242599819582722325
132
+ hash: 101138682589520811
133
133
  segments:
134
134
  - 0
135
135
  version: "0"