hana 1.2.1 → 1.3.0
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.
- checksums.yaml +4 -4
- data/README.md +7 -8
- data/lib/hana.rb +32 -20
- data/test/test_hana.rb +16 -0
- metadata +23 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47901af6a51be41cedcdbea157ab51919387f620
|
4
|
+
data.tar.gz: 533536f30bece16ab323ef9af184dbf7aca22e6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0720be506f273f9404ba4ac0f62b46599eec0935906e07542b6fbb95da6e5054193b87f96de888c7680cced1c543b551a193a02499f2b39cf3bfb597dc611e41
|
7
|
+
data.tar.gz: 840399954c106f206257c46f4d217a2ed06d23f84b92c0d30e59b65b77839c21d335ca806188da86621de5403195b4a941eefd421846576d3763af8a5dac8c4e
|
data/README.md
CHANGED
@@ -4,15 +4,14 @@
|
|
4
4
|
|
5
5
|
## DESCRIPTION:
|
6
6
|
|
7
|
-
Implementation of [JSON Patch][1] and [JSON Pointer][2]
|
7
|
+
Implementation of [JSON Patch][1] and [JSON Pointer][2] RFC.
|
8
8
|
|
9
9
|
## FEATURES/PROBLEMS:
|
10
10
|
|
11
|
-
Implements
|
11
|
+
Implements specs of the [JSON Patch][1] and [JSON pointer][2] RFCs:
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
should load the JSON to Ruby, process it, then emit as JSON again.
|
13
|
+
This works against Ruby objects, so you should load the JSON to Ruby,
|
14
|
+
process it, then emit as JSON again.
|
16
15
|
|
17
16
|
## SYNOPSIS:
|
18
17
|
|
@@ -36,7 +35,7 @@ patch.apply('foo' => 'bar') # => {'baz' => 'qux', 'foo' => 'bar'}
|
|
36
35
|
|
37
36
|
(The MIT License)
|
38
37
|
|
39
|
-
Copyright (c) 2012 Aaron Patterson
|
38
|
+
Copyright (c) 2012-2013 Aaron Patterson
|
40
39
|
|
41
40
|
Permission is hereby granted, free of charge, to any person obtaining
|
42
41
|
a copy of this software and associated documentation files (the
|
@@ -57,5 +56,5 @@ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
57
56
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
58
57
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
59
58
|
|
60
|
-
[1]:
|
61
|
-
[2]: http://tools.ietf.org/html/
|
59
|
+
[1]: https://datatracker.ietf.org/doc/rfc6902/
|
60
|
+
[2]: http://tools.ietf.org/html/rfc6901
|
data/lib/hana.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Hana
|
2
|
-
VERSION = '1.
|
2
|
+
VERSION = '1.3.0'
|
3
3
|
|
4
4
|
class Pointer
|
5
5
|
include Enumerable
|
@@ -9,7 +9,6 @@ module Hana
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def each(&block); @path.each(&block); end
|
12
|
-
def to_a; @path.dup; end
|
13
12
|
|
14
13
|
def eval object
|
15
14
|
Pointer.eval @path, object
|
@@ -19,6 +18,8 @@ module Hana
|
|
19
18
|
|
20
19
|
def self.eval list, object
|
21
20
|
list.inject(object) { |o, part|
|
21
|
+
return nil unless o
|
22
|
+
|
22
23
|
if Array === o
|
23
24
|
raise Patch::IndexError unless part =~ /\A\d+\Z/
|
24
25
|
part = part.to_i
|
@@ -30,8 +31,8 @@ module Hana
|
|
30
31
|
def self.parse path
|
31
32
|
return [''] if path == '/'
|
32
33
|
|
33
|
-
path.sub(/^\//, '').split(/(?<!\^)\//).
|
34
|
-
part.gsub!(/\^[\/^]|~[01]/) { |m| ESC[m] }
|
34
|
+
path.sub(/^\//, '').split(/(?<!\^)\//).each { |part|
|
35
|
+
part.gsub!(/\^[\/^]|~[01]/) { |m| ESC[m] }
|
35
36
|
}
|
36
37
|
end
|
37
38
|
end
|
@@ -69,8 +70,8 @@ module Hana
|
|
69
70
|
VALID = Hash[%w{ add move test replace remove copy }.map { |x| [x,x]}] # :nodoc:
|
70
71
|
|
71
72
|
def apply doc
|
72
|
-
@is.
|
73
|
-
send VALID.fetch(ins[
|
73
|
+
@is.inject(doc) { |d, ins|
|
74
|
+
send VALID.fetch(ins[OP].strip) { |k|
|
74
75
|
raise Exception, "bad method `#{k}`"
|
75
76
|
}, ins, d
|
76
77
|
}
|
@@ -78,24 +79,30 @@ module Hana
|
|
78
79
|
|
79
80
|
private
|
80
81
|
|
82
|
+
PATH = 'path' # :nodoc:
|
83
|
+
FROM = 'from' # :nodoc:
|
84
|
+
VALUE = 'value' # :nodoc:
|
85
|
+
OP = 'op' # :nodoc:
|
86
|
+
|
81
87
|
def add ins, doc
|
82
|
-
list = Pointer.parse ins[
|
88
|
+
list = Pointer.parse ins[PATH]
|
83
89
|
key = list.pop
|
84
90
|
dest = Pointer.eval list, doc
|
85
|
-
obj = ins[
|
91
|
+
obj = ins[VALUE]
|
86
92
|
|
87
|
-
raise(MissingTargetException, ins[
|
93
|
+
raise(MissingTargetException, ins[PATH]) unless dest
|
88
94
|
|
89
95
|
if key
|
90
96
|
add_op dest, key, obj
|
91
97
|
else
|
92
98
|
dest.replace obj
|
93
99
|
end
|
100
|
+
doc
|
94
101
|
end
|
95
102
|
|
96
103
|
def move ins, doc
|
97
|
-
from = Pointer.parse ins[
|
98
|
-
to = Pointer.parse ins[
|
104
|
+
from = Pointer.parse ins[FROM]
|
105
|
+
to = Pointer.parse ins[PATH]
|
99
106
|
from_key = from.pop
|
100
107
|
key = to.pop
|
101
108
|
src = Pointer.eval from, doc
|
@@ -103,11 +110,12 @@ module Hana
|
|
103
110
|
|
104
111
|
obj = rm_op src, from_key
|
105
112
|
add_op dest, key, obj
|
113
|
+
doc
|
106
114
|
end
|
107
115
|
|
108
116
|
def copy ins, doc
|
109
|
-
from = Pointer.parse ins[
|
110
|
-
to = Pointer.parse ins[
|
117
|
+
from = Pointer.parse ins[FROM]
|
118
|
+
to = Pointer.parse ins[PATH]
|
111
119
|
from_key = from.pop
|
112
120
|
key = to.pop
|
113
121
|
src = Pointer.eval from, doc
|
@@ -121,34 +129,38 @@ module Hana
|
|
121
129
|
end
|
122
130
|
|
123
131
|
add_op dest, key, obj
|
132
|
+
doc
|
124
133
|
end
|
125
134
|
|
126
135
|
def test ins, doc
|
127
|
-
expected = Pointer.new(ins[
|
136
|
+
expected = Pointer.new(ins[PATH]).eval doc
|
128
137
|
|
129
|
-
unless expected == ins[
|
130
|
-
raise FailedTestException.new(ins[
|
138
|
+
unless expected == ins[VALUE]
|
139
|
+
raise FailedTestException.new(ins[VALUE], ins[PATH])
|
131
140
|
end
|
141
|
+
doc
|
132
142
|
end
|
133
143
|
|
134
144
|
def replace ins, doc
|
135
|
-
list = Pointer.parse ins[
|
145
|
+
list = Pointer.parse ins[PATH]
|
136
146
|
key = list.pop
|
137
147
|
obj = Pointer.eval list, doc
|
138
148
|
|
139
149
|
if Array === obj
|
140
150
|
raise Patch::IndexError unless key =~ /\A\d+\Z/
|
141
|
-
obj[key.to_i] = ins[
|
151
|
+
obj[key.to_i] = ins[VALUE]
|
142
152
|
else
|
143
|
-
obj[key] = ins[
|
153
|
+
obj[key] = ins[VALUE]
|
144
154
|
end
|
155
|
+
doc
|
145
156
|
end
|
146
157
|
|
147
158
|
def remove ins, doc
|
148
|
-
list = Pointer.parse ins[
|
159
|
+
list = Pointer.parse ins[PATH]
|
149
160
|
key = list.pop
|
150
161
|
obj = Pointer.eval list, doc
|
151
162
|
rm_op obj, key
|
163
|
+
doc
|
152
164
|
end
|
153
165
|
|
154
166
|
def check_index obj, key
|
data/test/test_hana.rb
CHANGED
@@ -10,6 +10,14 @@ class TestHana < Hana::TestCase
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
def test_mutate_to_a_does_not_impact_original
|
14
|
+
pointer = Hana::Pointer.new '/foo/bar/baz'
|
15
|
+
x = pointer.to_a
|
16
|
+
x << "omg"
|
17
|
+
assert_equal %w{ foo bar baz omg }, x
|
18
|
+
assert_equal %w{ foo bar baz }, pointer.to_a
|
19
|
+
end
|
20
|
+
|
13
21
|
def test_split_many
|
14
22
|
pointer = Hana::Pointer.new '/foo/bar/baz'
|
15
23
|
assert_equal %w{ foo bar baz }, pointer.to_a
|
@@ -48,4 +56,12 @@ class TestHana < Hana::TestCase
|
|
48
56
|
pointer = Hana::Pointer.new '/foo/1'
|
49
57
|
assert_equal 'baz', pointer.eval('foo' => { '1' => 'baz' })
|
50
58
|
end
|
59
|
+
|
60
|
+
def test_eval_many_below_missing
|
61
|
+
pointer = Hana::Pointer.new '/baz/foo/bar'
|
62
|
+
assert_nil pointer.eval('foo' => 'bar')
|
63
|
+
|
64
|
+
pointer = Hana::Pointer.new '/foo/bar/baz'
|
65
|
+
assert_nil pointer.eval('foo' => nil)
|
66
|
+
end
|
51
67
|
end
|
metadata
CHANGED
@@ -1,58 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Patterson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5.
|
19
|
+
version: '5.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '5.
|
26
|
+
version: '5.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '4.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '4.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: hoe
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.13'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
55
|
-
description: Implementation of [JSON Patch][1] and [JSON Pointer][2]
|
54
|
+
version: '3.13'
|
55
|
+
description: Implementation of [JSON Patch][1] and [JSON Pointer][2] RFC.
|
56
56
|
email:
|
57
57
|
- aaron@tenderlovemaking.com
|
58
58
|
executables: []
|
@@ -62,7 +62,8 @@ extra_rdoc_files:
|
|
62
62
|
- Manifest.txt
|
63
63
|
- README.md
|
64
64
|
files:
|
65
|
-
- .autotest
|
65
|
+
- ".autotest"
|
66
|
+
- ".gemtest"
|
66
67
|
- CHANGELOG.rdoc
|
67
68
|
- Manifest.txt
|
68
69
|
- README.md
|
@@ -75,32 +76,32 @@ files:
|
|
75
76
|
- test/mine.json
|
76
77
|
- test/test_hana.rb
|
77
78
|
- test/test_ietf.rb
|
78
|
-
- .gemtest
|
79
79
|
homepage: http://github.com/tenderlove/hana
|
80
|
-
licenses:
|
80
|
+
licenses:
|
81
|
+
- MIT
|
81
82
|
metadata: {}
|
82
83
|
post_install_message:
|
83
84
|
rdoc_options:
|
84
|
-
- --main
|
85
|
+
- "--main"
|
85
86
|
- README.md
|
86
87
|
require_paths:
|
87
88
|
- lib
|
88
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
89
90
|
requirements:
|
90
|
-
- -
|
91
|
+
- - ">="
|
91
92
|
- !ruby/object:Gem::Version
|
92
93
|
version: '0'
|
93
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
95
|
requirements:
|
95
|
-
- -
|
96
|
+
- - ">="
|
96
97
|
- !ruby/object:Gem::Version
|
97
98
|
version: '0'
|
98
99
|
requirements: []
|
99
|
-
rubyforge_project:
|
100
|
-
rubygems_version: 2.
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.4.5
|
101
102
|
signing_key:
|
102
103
|
specification_version: 4
|
103
|
-
summary: Implementation of [JSON Patch][1] and [JSON Pointer][2]
|
104
|
+
summary: Implementation of [JSON Patch][1] and [JSON Pointer][2] RFC.
|
104
105
|
test_files:
|
105
106
|
- test/test_hana.rb
|
106
107
|
- test/test_ietf.rb
|