rubyfox-sfsobject 0.7.0-java → 0.8.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/README.md +2 -2
- data/lib/rubyfox/sfsobject/bulk.rb +38 -31
- data/lib/rubyfox/sfsobject/schema.rb +4 -4
- data/lib/rubyfox/sfsobject/version.rb +1 -1
- data/test/rubyfox/sfsobject/accessor_test.rb +12 -12
- data/test/rubyfox/sfsobject/bulk_test.rb +24 -24
- data/test/rubyfox/sfsobject/schema_test.rb +9 -9
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cbc395e880b6c8a4b07636b49e7266169200db71ce46d8b27f83324c03af15d
|
4
|
+
data.tar.gz: 17d13b29741f0448e2e2a261a48d68cfd9fe84b7db69f3a68d211dbfcc554194
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 366d114a0955eb824bc1aaf9531689db1652b5f1e4810a8fa09d1c2be29bb9bfb317731e3dfcf575506254d7cd1ca478482213a94a8fd880314a65fb1192b1e3
|
7
|
+
data.tar.gz: 53252d8adcf99713d9bb2d17ee8259df89dcaf2de339f6accfe40350edf5ab05a0b3cb4629cb3849747246759cd8884d10c1dfc1cb8cb473f9b1d57db337ada7
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Converts between SmartFox's SFSObjects and Ruby Hashes.
|
|
20
20
|
|
21
21
|
Add this line to your application's Gemfile:
|
22
22
|
|
23
|
-
gem 'rubyfox-sfsobject', '~> 0.
|
23
|
+
gem 'rubyfox-sfsobject', '~> 0.8.0'
|
24
24
|
|
25
25
|
And then execute:
|
26
26
|
|
@@ -28,7 +28,7 @@ And then execute:
|
|
28
28
|
|
29
29
|
Or install it yourself as:
|
30
30
|
|
31
|
-
$ gem install rubyfox-sfsobject -v 0.
|
31
|
+
$ gem install rubyfox-sfsobject -v 0.8.0
|
32
32
|
|
33
33
|
## Usage
|
34
34
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "rubyfox/sfsobject/java"
|
2
2
|
|
3
3
|
module Rubyfox
|
4
4
|
module SFSObject
|
@@ -6,24 +6,24 @@ module Rubyfox
|
|
6
6
|
extend self
|
7
7
|
|
8
8
|
TO_SFS = {
|
9
|
-
NilClass
|
10
|
-
String
|
11
|
-
TrueClass
|
12
|
-
FalseClass
|
13
|
-
|
14
|
-
Float
|
15
|
-
Hash
|
9
|
+
NilClass => proc { |o, k, _| o.putNull(k) },
|
10
|
+
String => :putUtfString,
|
11
|
+
TrueClass => :putBool,
|
12
|
+
FalseClass => :putBool,
|
13
|
+
Integer => :putInt,
|
14
|
+
Float => :putDouble,
|
15
|
+
Hash => proc { |o, k, v| o.putSFSObject(k, to_sfs(v)) },
|
16
16
|
Java::SFSObject => :putSFSObject,
|
17
|
-
[String]
|
18
|
-
[TrueClass]
|
19
|
-
[FalseClass]
|
20
|
-
[
|
17
|
+
[String] => :putUtfStringArray,
|
18
|
+
[TrueClass] => :putBoolArray,
|
19
|
+
[FalseClass] => :putBoolArray,
|
20
|
+
[Integer] => proc do |o, k, v|
|
21
21
|
collection = Java::ArrayList.new
|
22
22
|
v.each { |e| collection.add(e.to_java(:int)) }
|
23
23
|
o.putIntArray(k, collection)
|
24
24
|
end,
|
25
|
-
[Float]
|
26
|
-
[Hash]
|
25
|
+
[Float] => :putDoubleArray,
|
26
|
+
[Hash] => proc do |o, k, v|
|
27
27
|
ary = Java::SFSArray.new
|
28
28
|
v.each { |e| ary.addSFSObject(to_sfs(e)) }
|
29
29
|
o.putSFSArray(k, ary)
|
@@ -32,29 +32,29 @@ module Rubyfox
|
|
32
32
|
ary = Java::SFSArray.new
|
33
33
|
v.each { |e| ary.addSFSObject(e) }
|
34
34
|
o.putSFSArray(k, ary)
|
35
|
-
end
|
35
|
+
end,
|
36
36
|
}
|
37
37
|
|
38
38
|
TO_HASH = {
|
39
|
-
"NULL"
|
40
|
-
"UTF_STRING"
|
41
|
-
"BOOL"
|
42
|
-
"INT"
|
43
|
-
"DOUBLE"
|
44
|
-
"FLOAT"
|
45
|
-
"UTF_STRING_ARRAY"
|
46
|
-
"BOOL_ARRAY"
|
39
|
+
"NULL" => proc { |k, v| nil },
|
40
|
+
"UTF_STRING" => :getUtfString,
|
41
|
+
"BOOL" => :getBool,
|
42
|
+
"INT" => :getInt,
|
43
|
+
"DOUBLE" => :getDouble,
|
44
|
+
"FLOAT" => :getFloat,
|
45
|
+
"UTF_STRING_ARRAY" => :getUtfStringArray,
|
46
|
+
"BOOL_ARRAY" => :getBoolArray,
|
47
47
|
#"INT_ARRAY" => :getIntArray,
|
48
|
-
"INT_ARRAY"
|
49
|
-
"LONG_ARRAY"
|
50
|
-
"DOUBLE_ARRAY"
|
51
|
-
"FLOAT_ARRAY"
|
52
|
-
"SFS_OBJECT"
|
53
|
-
"SFS_ARRAY"
|
48
|
+
"INT_ARRAY" => proc { |k, v| v.object.to_a },
|
49
|
+
"LONG_ARRAY" => :getLongArray,
|
50
|
+
"DOUBLE_ARRAY" => :getDoubleArray,
|
51
|
+
"FLOAT_ARRAY" => :getFloatArray,
|
52
|
+
"SFS_OBJECT" => proc { |k, v| to_hash(v.object) },
|
53
|
+
"SFS_ARRAY" => proc { |k, v| to_array(v.object) },
|
54
54
|
}
|
55
55
|
|
56
56
|
# hash -> object
|
57
|
-
def to_sfs(hash={})
|
57
|
+
def to_sfs(hash = {})
|
58
58
|
object = Java::SFSObject.new
|
59
59
|
hash.each do |key, value|
|
60
60
|
wrap_value!(object, key, value)
|
@@ -78,7 +78,14 @@ module Rubyfox
|
|
78
78
|
def _wrapper(value)
|
79
79
|
case value
|
80
80
|
when Array
|
81
|
-
|
81
|
+
case value = value.first
|
82
|
+
when Integer # This is necessary to support ruby < 2.4.
|
83
|
+
TO_SFS[[Integer]]
|
84
|
+
else
|
85
|
+
TO_SFS[[value.class]]
|
86
|
+
end
|
87
|
+
when Integer # See above.
|
88
|
+
TO_SFS[Integer]
|
82
89
|
else
|
83
90
|
TO_SFS[value.class]
|
84
91
|
end
|
@@ -17,12 +17,12 @@ module Rubyfox
|
|
17
17
|
TO_SFS = {
|
18
18
|
String => proc { |o, s, k, v| o.put_utf_string(k, v) },
|
19
19
|
Boolean => proc { |o, s, k, v| o.put_bool(k, v) },
|
20
|
-
|
20
|
+
Integer => proc { |o, s, k, v| o.put_int(k, v) },
|
21
21
|
Float => proc { |o, s, k, v| o.put_double(k, v) },
|
22
22
|
Hash => proc { |o, s, k, v| o.put_sfs_object(k, to_sfs(s, v)) },
|
23
23
|
[String] => proc { |o, s, k, v| o.put_utf_string_array(k, v) },
|
24
24
|
[Boolean] => proc { |o, s, k, v| o.put_bool_array(k, v) },
|
25
|
-
[
|
25
|
+
[Integer] => proc do |o, s, k, v|
|
26
26
|
collection = Java::ArrayList.new(v.size)
|
27
27
|
v.each { |e| collection.add(e.to_java(:int)) }
|
28
28
|
o.put_int_array(k, collection)
|
@@ -39,12 +39,12 @@ module Rubyfox
|
|
39
39
|
TO_HASH = {
|
40
40
|
String => proc { |o, s, k| o.get_utf_string(k) },
|
41
41
|
Boolean => proc { |o, s, k| o.get_bool(k) },
|
42
|
-
|
42
|
+
Integer => proc { |o, s, k| o.get_int(k) },
|
43
43
|
Float => proc { |o, s, k| o.get_double(k) },
|
44
44
|
Hash => proc { |o, s, k| to_hash(s, o.get_sfs_object(k)) },
|
45
45
|
[String] => proc { |o, s, k| o.get_utf_string_array(k).to_a },
|
46
46
|
[Boolean] => proc { |o, s, k| o.get_bool_array(k).to_a },
|
47
|
-
[
|
47
|
+
[Integer] => proc { |o, s, k| o.get_int_array(k).to_a },
|
48
48
|
[Float] => proc { |o, s, k| o.get_double_array(k).to_a },
|
49
49
|
[Hash] => proc { |o, s, k|
|
50
50
|
sfs_ary = o.get_sfs_array(k)
|
@@ -18,9 +18,9 @@ class RubyfoxSFSObjectAccessorTest < RubyfoxCase
|
|
18
18
|
|
19
19
|
context "SFSObject[]" do
|
20
20
|
test "sets hash" do
|
21
|
-
object = Rubyfox::SFSObject[:string => "value", :sub => { :
|
21
|
+
object = Rubyfox::SFSObject[:string => "value", :sub => { :integer => 23 }]
|
22
22
|
assert_equal "value", object[:string]
|
23
|
-
assert_equal 23, object[:sub][:
|
23
|
+
assert_equal 23, object[:sub][:integer]
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -51,21 +51,21 @@ class RubyfoxSFSObjectAccessorTest < RubyfoxCase
|
|
51
51
|
assert_accessor :true => true, :false => false
|
52
52
|
end
|
53
53
|
|
54
|
-
test "
|
55
|
-
assert_accessor :
|
56
|
-
assert_accessor :
|
57
|
-
assert_accessor :
|
54
|
+
test "integer" do
|
55
|
+
assert_accessor :integer => 1
|
56
|
+
assert_accessor :integer => (2 ** 31 - 1)
|
57
|
+
assert_accessor :integer => -(2 ** 31)
|
58
58
|
end
|
59
59
|
|
60
|
-
test "
|
60
|
+
test "integer too big for int" do
|
61
61
|
assert_raises RangeError, :message => /too big for int/ do
|
62
|
-
assert_accessor :
|
62
|
+
assert_accessor :integer => (2 ** 31)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
test "cannot handle bignum" do
|
67
|
-
assert_raises
|
68
|
-
assert_accessor :
|
67
|
+
assert_raises RangeError, :message => /bignum too big/ do
|
68
|
+
assert_accessor :integer => (2 ** 63)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -92,8 +92,8 @@ class RubyfoxSFSObjectAccessorTest < RubyfoxCase
|
|
92
92
|
assert_accessor :bool => [ true, false ]
|
93
93
|
end
|
94
94
|
|
95
|
-
test "
|
96
|
-
assert_accessor :
|
95
|
+
test "integer" do
|
96
|
+
assert_accessor :integer => [ 1, 2, 3 ]
|
97
97
|
end
|
98
98
|
|
99
99
|
test "float" do
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# encoding: utf-8
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "helper"
|
4
|
+
require "rubyfox/sfsobject/bulk"
|
5
5
|
|
6
6
|
class RubyfoxSFSObjectBulkTest < RubyfoxCase
|
7
7
|
test "empty" do
|
@@ -9,7 +9,7 @@ class RubyfoxSFSObjectBulkTest < RubyfoxCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
test "converts keys to symbols" do
|
12
|
-
assert_conversion({
|
12
|
+
assert_conversion({"key" => nil}, {:key => nil})
|
13
13
|
end
|
14
14
|
|
15
15
|
test "raise ArgumentError for nil values" do
|
@@ -33,21 +33,21 @@ class RubyfoxSFSObjectBulkTest < RubyfoxCase
|
|
33
33
|
assert_conversion :true => true, :false => false
|
34
34
|
end
|
35
35
|
|
36
|
-
test "
|
37
|
-
assert_conversion :
|
38
|
-
assert_conversion :
|
39
|
-
assert_conversion :
|
36
|
+
test "integer" do
|
37
|
+
assert_conversion :integer => 1
|
38
|
+
assert_conversion :integer => (2 ** 31 - 1)
|
39
|
+
assert_conversion :integer => -(2 ** 31)
|
40
40
|
end
|
41
41
|
|
42
|
-
test "
|
42
|
+
test "integer too big for int" do
|
43
43
|
assert_raises RangeError, :message => /too big for int/ do
|
44
|
-
assert_conversion :
|
44
|
+
assert_conversion :integer => (2 ** 31)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
test "cannot handle bignum" do
|
49
|
-
assert_raises
|
50
|
-
assert_conversion :
|
49
|
+
assert_raises RangeError, :message => /bignum too big/ do
|
50
|
+
assert_conversion :integer => (2 ** 63)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -73,12 +73,12 @@ class RubyfoxSFSObjectBulkTest < RubyfoxCase
|
|
73
73
|
end
|
74
74
|
|
75
75
|
test "sub hashes" do
|
76
|
-
assert_conversion :sub => {
|
77
|
-
assert_conversion :sub => {
|
76
|
+
assert_conversion :sub => {:key => "value"}
|
77
|
+
assert_conversion :sub => {:deep => {:key => "value"}}
|
78
78
|
end
|
79
79
|
|
80
80
|
test "sfsobject" do
|
81
|
-
assert_conversion({
|
81
|
+
assert_conversion({:sfsobject => Rubyfox::SFSObject.new}, {:sfsobject => {}})
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -91,15 +91,15 @@ class RubyfoxSFSObjectBulkTest < RubyfoxCase
|
|
91
91
|
end
|
92
92
|
|
93
93
|
test "boolean" do
|
94
|
-
assert_conversion :bool => [
|
94
|
+
assert_conversion :bool => [true, false]
|
95
95
|
end
|
96
96
|
|
97
|
-
test "
|
98
|
-
assert_conversion :
|
97
|
+
test "integer" do
|
98
|
+
assert_conversion :integer => [1, 2, 3]
|
99
99
|
end
|
100
100
|
|
101
101
|
test "float" do
|
102
|
-
assert_conversion :float => [
|
102
|
+
assert_conversion :float => [1.0, 1.0 / 3]
|
103
103
|
end
|
104
104
|
|
105
105
|
test "converts Java's double array to Ruby's Float array" do
|
@@ -119,12 +119,12 @@ class RubyfoxSFSObjectBulkTest < RubyfoxCase
|
|
119
119
|
end
|
120
120
|
|
121
121
|
test "sub hashes" do
|
122
|
-
assert_conversion :sub => [{
|
123
|
-
assert_conversion :sub => [{
|
122
|
+
assert_conversion :sub => [{:key => "value"}]
|
123
|
+
assert_conversion :sub => [{:deep => [{:key => "value"}]}]
|
124
124
|
end
|
125
125
|
|
126
126
|
test "sfsobject" do
|
127
|
-
assert_conversion({
|
127
|
+
assert_conversion({:sfsobject => [Rubyfox::SFSObject.new]}, {:sfsobject => [{}]})
|
128
128
|
end
|
129
129
|
|
130
130
|
test "loads mixed arrays" do
|
@@ -137,7 +137,7 @@ class RubyfoxSFSObjectBulkTest < RubyfoxCase
|
|
137
137
|
}
|
138
138
|
]}')
|
139
139
|
expected = {
|
140
|
-
|
140
|
+
:mixed => ["foo", true, 1.0, {:deep => ["Föhn", "BÄR"]}],
|
141
141
|
}
|
142
142
|
assert_equal expected, Rubyfox::SFSObject::Bulk.to_hash(object)
|
143
143
|
end
|
@@ -145,7 +145,7 @@ class RubyfoxSFSObjectBulkTest < RubyfoxCase
|
|
145
145
|
|
146
146
|
private
|
147
147
|
|
148
|
-
def assert_conversion(input, output=input)
|
148
|
+
def assert_conversion(input, output = input)
|
149
149
|
object = Rubyfox::SFSObject::Bulk.to_sfs(input)
|
150
150
|
assert_equal output, Rubyfox::SFSObject::Bulk.to_hash(object)
|
151
151
|
end
|
@@ -26,15 +26,15 @@ class RubyfoxSFSObjectSchemaTest < RubyfoxCase
|
|
26
26
|
assert_schema({ :bool => Boolean }, { :bool => false })
|
27
27
|
end
|
28
28
|
|
29
|
-
test "
|
30
|
-
assert_schema({ :
|
31
|
-
assert_schema({ :
|
32
|
-
assert_schema({ :
|
29
|
+
test "integer" do
|
30
|
+
assert_schema({ :integer => Integer }, { :integer => 1 })
|
31
|
+
assert_schema({ :integer => Integer }, { :integer => (2 ** 31 - 1) })
|
32
|
+
assert_schema({ :integer => Integer }, { :integer => -(2 ** 31) })
|
33
33
|
end
|
34
34
|
|
35
|
-
test "
|
35
|
+
test "integer too big for int" do
|
36
36
|
assert_raises RangeError, :message => /too big for int/ do
|
37
|
-
assert_schema({ :
|
37
|
+
assert_schema({ :integer => Integer }, { :integer => (2 ** 31) })
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -69,9 +69,9 @@ class RubyfoxSFSObjectSchemaTest < RubyfoxCase
|
|
69
69
|
assert_schema({ :bool => [Boolean] }, { :bool => [true, 23] }) # strange?
|
70
70
|
end
|
71
71
|
|
72
|
-
test "
|
73
|
-
assert_schema({ :
|
74
|
-
assert_schema({ :
|
72
|
+
test "integer" do
|
73
|
+
assert_schema({ :integer => [Integer] }, { :integer => [1, 2] })
|
74
|
+
assert_schema({ :integer => [Integer] }, { :integer => [(2 ** 31 - 1), -(2 ** 31)] })
|
75
75
|
end
|
76
76
|
|
77
77
|
test "float" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyfox-sfsobject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Peter Suschlik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.6
|
104
|
+
rubygems_version: 2.7.6
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: ''
|