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 +2 -0
- data/lib/rubyfox/sfsobject/accessor.rb +14 -0
- data/lib/rubyfox/sfsobject/core_ext.rb +2 -6
- data/lib/rubyfox/sfsobject/version.rb +1 -1
- data/lib/rubyfox/sfsobject.rb +5 -1
- data/test/rubyfox/sfsobject/accessor_test.rb +8 -0
- data/test/rubyfox/sfsobject/basic_test.rb +1 -1
- metadata +1 -1
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
|
data/lib/rubyfox/sfsobject.rb
CHANGED
@@ -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
|