rubyfox-sfsobject 0.2.1-java → 0.2.2-java

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -59,6 +59,8 @@ You can extend Hash and SFSObject with method shortcuts:
59
59
  ==== Hash-like access
60
60
 
61
61
  require 'rubyfox/sfsobject/core_ext'
62
+ sfs_object = Rubyfox::SFSObject[:meaning_of_life => 42]
63
+ sfs_object[:meaning_of_life] # => 42
62
64
  sfs_object[:string] = "value"
63
65
  sfs_object[:string] # => "value"
64
66
 
@@ -3,6 +3,20 @@ require 'rubyfox/sfsobject/bulk'
3
3
  module Rubyfox
4
4
  module SFSObject
5
5
  module Accessor
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ def [](hash)
12
+ new.tap do |sfs_object|
13
+ hash.each do |key, value|
14
+ sfs_object[key] = value
15
+ end
16
+ end
17
+ end
18
+ end
19
+
6
20
  def [](key)
7
21
  Bulk.unwrap_value!(self, key)
8
22
  end
@@ -26,11 +26,7 @@ class Rubyfox::SFSObject::Java::SFSObject
26
26
  end
27
27
  end
28
28
 
29
- def self.from_json(data)
30
- if data == "{}"
31
- new
32
- else
33
- new_from_json_data(data)
34
- end
29
+ class << self
30
+ alias :from_json :new_from_json_data
35
31
  end
36
32
  end
@@ -1,5 +1,5 @@
1
1
  module Rubyfox
2
2
  module SFSObject
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -19,7 +19,11 @@ module Rubyfox
19
19
  end
20
20
 
21
21
  def self.from_json(data)
22
- Java::SFSObject.new_from_json_data(data)
22
+ Java::SFSObject.from_json(data)
23
+ end
24
+
25
+ def self.[](*args)
26
+ Java::SFSObject[*args]
23
27
  end
24
28
  end
25
29
  end
@@ -16,6 +16,14 @@ class RubyfoxSFSObjectAccessorTest < RubyfoxCase
16
16
  assert_equal 2, sfs_object["symbol"]
17
17
  end
18
18
 
19
+ context "SFSObject[]" do
20
+ test "sets hash" do
21
+ object = Rubyfox::SFSObject[:string => "value", :sub => { :fixnum => 23 }]
22
+ assert_equal "value", object[:string]
23
+ assert_equal 23, object[:sub][:fixnum]
24
+ end
25
+ end
26
+
19
27
  context "plain" do
20
28
  test "nil" do
21
29
  assert_accessor :null => nil
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- require 'rubyfox/sfsobject/java'
3
+ require 'rubyfox/sfsobject/core_ext'
4
4
 
5
5
  class RubyfoxSFSObjectBasicTest < RubyfoxCase
6
6
  let(:sfs_object) { Rubyfox::SFSObject.new }
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rubyfox-sfsobject
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
5
+ version: 0.2.2
6
6
  platform: java
7
7
  authors:
8
8
  - Peter Suschlik