pigeon_hole 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pigeon_hole.rb +11 -12
  3. data/lib/pigeon_hole/json_date.rb +9 -20
  4. data/lib/pigeon_hole/json_symbol.rb +8 -14
  5. data/lib/pigeon_hole/json_time.rb +9 -16
  6. data/lib/pigeon_hole/typed_json.rb +68 -30
  7. data/spec/integration_spec.rb +22 -6
  8. data/spec/spec_helper.rb +2 -16
  9. metadata +4 -75
  10. data/lib/pigeon_hole/json_date_time.rb +0 -28
  11. data/lib/pigeon_hole/monster-vim-2016-07-25-16-44-46.rb +0 -29
  12. data/lib/pigeon_hole/monster-vim-2016-07-25-16-44-47.rb +0 -29
  13. data/lib/pigeon_hole/monster-vim-2016-07-25-16-44-58.rb +0 -41
  14. data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-02.rb +0 -41
  15. data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-08.rb +0 -41
  16. data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-09.rb +0 -41
  17. data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-10.rb +0 -41
  18. data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-35.rb +0 -29
  19. data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-36.rb +0 -29
  20. data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-37.rb +0 -29
  21. data/lib/pigeon_hole/monster-vim-2016-07-25-16-47-38.rb +0 -29
  22. data/lib/pigeon_hole/monster-vim-2016-07-26-10-09-11.rb +0 -41
  23. data/lib/pigeon_hole/monster-vim-2016-07-26-10-09-41.rb +0 -34
  24. data/lib/pigeon_hole/monster-vim-2016-07-26-10-09-42.rb +0 -34
  25. data/lib/pigeon_hole/monster-vim-2016-07-26-10-11-26.rb +0 -35
  26. data/lib/pigeon_hole/monster-vim-2016-07-26-10-15-33.rb +0 -39
  27. data/lib/pigeon_hole/monster-vim-2016-07-26-10-15-46.rb +0 -40
  28. data/lib/pigeon_hole/monster-vim-2016-07-26-10-15-57.rb +0 -37
  29. data/lib/pigeon_hole/monster-vim-2016-07-26-10-16-03.rb +0 -27
  30. data/lib/pigeon_hole/monster-vim-2016-07-26-10-16-04.rb +0 -27
  31. data/lib/pigeon_hole/monster-vim-2016-07-26-10-16-05.rb +0 -27
  32. data/lib/pigeon_hole/monster-vim-2016-07-26-10-17-22.rb +0 -28
  33. data/lib/pigeon_hole/monster-vim-2016-07-26-10-17-23.rb +0 -28
  34. data/lib/pigeon_hole/monster-vim-2016-07-26-10-19-14.rb +0 -28
  35. data/lib/pigeon_hole/monster-vim-2016-07-26-10-20-50.rb +0 -28
  36. data/lib/pigeon_hole/monster-vim-2016-07-26-10-20-52.rb +0 -28
  37. data/lib/pigeon_hole/monster-vim-2016-07-26-10-20-53.rb +0 -28
  38. data/lib/pigeon_hole/monster-vim-2016-07-26-10-26-57.rb +0 -42
  39. data/lib/pigeon_hole/monster-vim-2016-07-26-10-26-58.rb +0 -42
  40. data/lib/pigeon_hole/monster-vim-2016-07-26-10-27-58.rb +0 -42
  41. data/lib/pigeon_hole/monster-vim-2016-07-26-10-27-59.rb +0 -42
  42. data/lib/pigeon_hole/monster-vim-2016-07-26-10-33-40.rb +0 -42
  43. data/lib/pigeon_hole/monster-vim-2016-07-26-10-33-41.rb +0 -42
  44. data/lib/pigeon_hole/monster-vim-2016-07-26-10-33-42.rb +0 -42
  45. data/lib/pigeon_hole/monster-vim-2016-07-26-10-33-53.rb +0 -42
  46. data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-07.rb +0 -42
  47. data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-08.rb +0 -42
  48. data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-09.rb +0 -42
  49. data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-20.rb +0 -44
  50. data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-21.rb +0 -44
  51. data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-22.rb +0 -44
  52. data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-23.rb +0 -44
  53. data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-24.rb +0 -44
  54. data/lib/pigeon_hole/monster-vim-2016-07-26-10-37-25.rb +0 -44
  55. data/lib/pigeon_hole/monster-vim-2016-07-26-10-38-26.rb +0 -53
  56. data/lib/pigeon_hole/monster-vim-2016-07-26-10-38-27.rb +0 -53
  57. data/lib/pigeon_hole/monster-vim-2016-07-26-10-38-28.rb +0 -53
  58. data/lib/pigeon_hole/monster-vim-2016-07-26-10-38-29.rb +0 -53
  59. data/lib/pigeon_hole/monster-vim-2016-07-26-10-39-14.rb +0 -53
  60. data/spec/monster-vim-2016-07-26-10-29-02.rb +0 -117
  61. data/spec/monster-vim-2016-07-26-10-29-53.rb +0 -118
  62. data/spec/monster-vim-2016-07-26-12-05-32.rb +0 -117
  63. data/spec/monster-vim-2016-07-26-12-05-33.rb +0 -117
  64. data/spec/monster-vim-2016-07-26-12-05-34.rb +0 -117
  65. data/spec/monster-vim-2016-07-26-12-05-35.rb +0 -117
  66. data/spec/monster-vim-2016-07-26-12-06-22.rb +0 -33
  67. data/spec/monster-vim-2016-07-26-12-06-32.rb +0 -33
  68. data/spec/monster-vim-2016-07-26-12-06-33.rb +0 -33
  69. data/spec/monster-vim-2016-07-26-12-06-34.rb +0 -33
@@ -1,53 +0,0 @@
1
- require 'json'
2
-
3
- module PigeonHole
4
- class TypedJSON
5
- def self.generate(obj, *args)
6
- hash_dup = each_with_parent(obj)
7
- JSON.generate(hash_dup, *args)
8
- end
9
-
10
- def self.map_to_json(obj)
11
- case obj
12
- when Time
13
- JSONTime.new(obj)
14
- when DateTime
15
- JSONDateTime.new(obj)
16
- when Date
17
- JSONDate.new(obj)
18
- when Symbol
19
- JSONSymbol.new(obj)
20
- else
21
- obj
22
- end
23
- end
24
-
25
- def self.map_array_value(value)
26
- case value
27
- when Hash
28
- each_with_parent(value)
29
- when Array
30
- value.mamap_array_value
31
- else
32
- map_to_json(value)
33
- end
34
- end
35
-
36
- def self.each_with_parent(hash, result=nil)
37
- duplicated_hash = {} || result
38
-
39
- hash.each do |k, v|
40
- case v
41
- when Hash
42
- duplicated_hash[k] = each_with_parent(v, duplicated_hash)
43
- when Array
44
- duplicated_hash[k] = v.map { |av| map_to_json(av) map_to_json(av) }.to_a
45
- else
46
- duplicated_hash[k] = map_to_json(v)
47
- end
48
- end
49
-
50
- duplicated_hash
51
- end
52
- end
53
- end
@@ -1,53 +0,0 @@
1
- require 'json'
2
-
3
- module PigeonHole
4
- class TypedJSON
5
- def self.generate(obj, *args)
6
- hash_dup = each_with_parent(obj)
7
- JSON.generate(hash_dup, *args)
8
- end
9
-
10
- def self.map_to_json(obj)
11
- case obj
12
- when Time
13
- JSONTime.new(obj)
14
- when DateTime
15
- JSONDateTime.new(obj)
16
- when Date
17
- JSONDate.new(obj)
18
- when Symbol
19
- JSONSymbol.new(obj)
20
- else
21
- obj
22
- end
23
- end
24
-
25
- def self.map_array_value(value)
26
- case value
27
- when Hash
28
- each_with_parent(value)
29
- when Array
30
- value.map(&:map_array_value)
31
- else
32
- map_to_json(value)
33
- end
34
- end
35
-
36
- def self.each_with_parent(hash, result=nil)
37
- duplicated_hash = {} || result
38
-
39
- hash.each do |k, v|
40
- case v
41
- when Hash
42
- duplicated_hash[k] = each_with_parent(v, duplicated_hash)
43
- when Array
44
- duplicated_hash[k] = v.map
45
- else
46
- duplicated_hash[k] = map_to_json(v)
47
- end
48
- end
49
-
50
- duplicated_hash
51
- end
52
- end
53
- end
@@ -1,117 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "serializing dates" do
4
- let(:date) { random_date }
5
-
6
- subject { PigeonHole.generate(date: date) }
7
-
8
- it "serializes hash into a string" do
9
- result = subject
10
- expect(result).to_not be_empty
11
- end
12
-
13
- it "can be deserialized to a date time" do
14
- result = subject
15
- hash = PigeonHole.parse(result)
16
- expect(hash).to eq({ "date" => date })
17
- expect(hash["date"]).to be_a(Date)
18
- end
19
- end
20
-
21
- describe "serializing times" do
22
- let(:time) { random_time }
23
-
24
- subject { PigeonHole.generate(time: time) }
25
-
26
- it "serializes hash into a string" do
27
- result = subject
28
- expect(result).to_not be_empty
29
- end
30
-
31
- it "can be deserialized to a time" do
32
- result = subject
33
- hash = PigeonHole.parse(result)
34
- expect(hash).to eq({ "time" => time })
35
- expect(hash["time"]).to be_a(Time)
36
- end
37
- end
38
-
39
- describe "serializing datetimes" do
40
- let(:date_time) { random_date_time }
41
-
42
- subject { PigeonHole.generate(date_time: date_time) }
43
-
44
- it "serializes hash into a string" do
45
- result = subject
46
- expect(result).to_not be_empty
47
- end
48
-
49
- it "can be deserialized to a date_time" do
50
- result = subject
51
- hash = PigeonHole.parse(result)
52
- expect(hash["date_time"]).to be_a(DateTime)
53
- expect(hash["date_time"].to_date).to eq(date_time.to_date)
54
- expect(hash["date_time"].to_time.to_i).to eq(date_time.to_time.to_i)
55
- end
56
- end
57
-
58
- describe "serializing symbols" do
59
- let(:symbol) { :a_symbol }
60
-
61
- subject { PigeonHole.generate(symbol: symbol) }
62
-
63
- it "serializes hash into a string" do
64
- result = subject
65
- expect(result).to_not be_empty
66
- end
67
-
68
- it "can be deserialized to a symbol" do
69
- result = subject
70
- hash = PigeonHole.parse(result)
71
- expect(hash).to eq({ "symbol" => symbol })
72
- expect(hash["symbol"]).to be_a(Symbol)
73
- end
74
- end
75
-
76
- describe "serializing arrays" do
77
- let(:symbol) { [:a_symbol] }
78
-
79
- subject { PigeonHole.generate(symbol: symbol) }
80
-
81
- it "serializes hash into a string" do
82
- result = subject
83
- expect(result).to_not be_empty
84
- end
85
-
86
- it "can be deserialized to a symbol" do
87
- result = subject
88
- hash = PigeonHole.parse(result)
89
- expect(hash).to eq({ "symbol" => symbol })
90
- expect(hash["symbol"].first).to be_a(Symbol)
91
- end
92
- end
93
-
94
- describe "serializing nested hashes" do
95
- let(:expected) do
96
- {
97
- foo: {
98
- bar: random_time,
99
- baz: :temp
100
- }
101
- }
102
- end
103
-
104
- subject { PigeonHole.generate(expected) }
105
-
106
- it "serializes hash into a string" do
107
- result = subject
108
- expect(result).to_not be_empty
109
- end
110
-
111
- it "can be deserialized to a symbol" do
112
- result = subject
113
- hash = PigeonHole.parse(result)
114
-
115
- expect(symbolize_hash(hash)).to eq(expected)
116
- end
117
- end
@@ -1,118 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "serializing dates" do
4
- let(:date) { random_date }
5
-
6
- subject { PigeonHole.generate(date: date) }
7
-
8
- it "serializes hash into a string" do
9
- result = subject
10
- expect(result).to_not be_empty
11
- end
12
-
13
- it "can be deserialized to a date time" do
14
- result = subject
15
- hash = PigeonHole.parse(result)
16
- expect(hash).to eq({ "date" => date })
17
- expect(hash["date"]).to be_a(Date)
18
- end
19
- end
20
-
21
- describe "serializing times" do
22
- let(:time) { random_time }
23
-
24
- subject { PigeonHole.generate(time: time) }
25
-
26
- it "serializes hash into a string" do
27
- result = subject
28
- expect(result).to_not be_empty
29
- end
30
-
31
- it "can be deserialized to a time" do
32
- result = subject
33
- hash = PigeonHole.parse(result)
34
- expect(hash).to eq({ "time" => time })
35
- expect(hash["time"]).to be_a(Time)
36
- end
37
- end
38
-
39
- describe "serializing datetimes" do
40
- let(:date_time) { random_date_time }
41
-
42
- subject { PigeonHole.generate(date_time: date_time) }
43
-
44
- it "serializes hash into a string" do
45
- result = subject
46
- expect(result).to_not be_empty
47
- end
48
-
49
- it "can be deserialized to a date_time" do
50
- result = subject
51
- hash = PigeonHole.parse(result)
52
- expect(hash["date_time"]).to be_a(DateTime)
53
- expect(hash["date_time"].to_date).to eq(date_time.to_date)
54
- expect(hash["date_time"].to_time.to_i).to eq(date_time.to_time.to_i)
55
- end
56
- end
57
-
58
- describe "serializing symbols" do
59
- let(:symbol) { :a_symbol }
60
-
61
- subject { PigeonHole.generate(symbol: symbol) }
62
-
63
- it "serializes hash into a string" do
64
- result = subject
65
- expect(result).to_not be_empty
66
- end
67
-
68
- it "can be deserialized to a symbol" do
69
- result = subject
70
- hash = PigeonHole.parse(result)
71
- expect(hash).to eq({ "symbol" => symbol })
72
- expect(hash["symbol"]).to be_a(Symbol)
73
- end
74
- end
75
-
76
- describe "serializing arrays" do
77
- let(:symbol) { [:a_symbol] }
78
-
79
- subject { PigeonHole.generate(symbol: symbol) }
80
-
81
- it "serializes hash into a string" do
82
- result = subject
83
- expect(result).to_not be_empty
84
- end
85
-
86
- it "can be deserialized to a symbol" do
87
- result = subject
88
- hash = PigeonHole.parse(result)
89
- expect(hash).to eq({ [ "symbol" => symbol ] })
90
- expect(hash["symbol"]).to
91
- expect(hash["symbol"].first).to be_a(Symbol)
92
- end
93
- end
94
-
95
- describe "serializing nested hashes" do
96
- let(:expected) do
97
- {
98
- foo: {
99
- bar: random_time,
100
- baz: :temp
101
- }
102
- }
103
- end
104
-
105
- subject { PigeonHole.generate(expected) }
106
-
107
- it "serializes hash into a string" do
108
- result = subject
109
- expect(result).to_not be_empty
110
- end
111
-
112
- it "can be deserialized to a symbol" do
113
- result = subject
114
- hash = PigeonHole.parse(result)
115
-
116
- expect(symbolize_hash(hash)).to eq(expected)
117
- end
118
- end
@@ -1,117 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "serializing dates" do
4
- let(:date) { random_date }
5
-
6
- subject { PigeonHole.generate(date: date) }
7
-
8
- it "serializes hash into a string" do
9
- result = subject
10
- expect(result).to_not be_empty
11
- end
12
-
13
- it "can be deserialized to a date time" do
14
- result = subject
15
- hash = PigeonHole.parse(result)
16
- expect(hash).to eq({ "date" => date })
17
- expect(hash["date"]).to be_a(Date)
18
- end
19
- end
20
-
21
- describe "serializing times" do
22
- let(:time) { random_time. }
23
-
24
- subject { PigeonHole.generate(time: time) }
25
-
26
- it "serializes hash into a string" do
27
- result = subject
28
- expect(result).to_not be_empty
29
- end
30
-
31
- it "can be deserialized to a time" do
32
- result = subject
33
- hash = PigeonHole.parse(result)
34
- expect(hash).to eq({ "time" => time })
35
- expect(hash["time"]).to be_a(Time)
36
- end
37
- end
38
-
39
- describe "serializing datetimes" do
40
- let(:date_time) { random_date_time }
41
-
42
- subject { PigeonHole.generate(date_time: date_time) }
43
-
44
- it "serializes hash into a string" do
45
- result = subject
46
- expect(result).to_not be_empty
47
- end
48
-
49
- it "can be deserialized to a date_time" do
50
- result = subject
51
- hash = PigeonHole.parse(result)
52
- expect(hash["date_time"]).to be_a(DateTime)
53
- expect(hash["date_time"].to_date).to eq(date_time.to_date)
54
- expect(hash["date_time"].to_time.to_i).to eq(date_time.to_time.to_i)
55
- end
56
- end
57
-
58
- describe "serializing symbols" do
59
- let(:symbol) { :a_symbol }
60
-
61
- subject { PigeonHole.generate(symbol: symbol) }
62
-
63
- it "serializes hash into a string" do
64
- result = subject
65
- expect(result).to_not be_empty
66
- end
67
-
68
- it "can be deserialized to a symbol" do
69
- result = subject
70
- hash = PigeonHole.parse(result)
71
- expect(hash).to eq({ "symbol" => symbol })
72
- expect(hash["symbol"]).to be_a(Symbol)
73
- end
74
- end
75
-
76
- describe "serializing arrays" do
77
- let(:array) { [:a_symbol, { "test" => :foo } ] }
78
-
79
- subject { PigeonHole.generate(array: array) }
80
-
81
- it "serializes hash into a string" do
82
- result = subject
83
- expect(result).to_not be_empty
84
- end
85
-
86
- it "can be deserialized to a array" do
87
- result = subject
88
- hash = PigeonHole.parse(result)
89
- expect(hash).to eq({ "array" => array })
90
- expect(hash["array"]).to be_a(Array)
91
- end
92
- end
93
-
94
- describe "serializing nested hashes" do
95
- let(:expected) do
96
- {
97
- foo: {
98
- bar: random_time,
99
- baz: :temp
100
- }
101
- }
102
- end
103
-
104
- subject { PigeonHole.generate(expected) }
105
-
106
- it "serializes hash into a string" do
107
- result = subject
108
- expect(result).to_not be_empty
109
- end
110
-
111
- it "can be deserialized to a symbol" do
112
- result = subject
113
- hash = PigeonHole.parse(result)
114
-
115
- expect(symbolize_hash(hash)).to eq(expected)
116
- end
117
- end