Rubyfox::SFSObject <img src=“https://secure.travis-ci.org/neopoly/rubyfox-sfsobject.png?branch=master” alt=“Build Status” />
Converts between SmartFox’s SFSObjects and Ruby Hashes.
Gem | Source | Documentation
Installation
Add this line to your application’s Gemfile:
gem 'rubyfox-sfsobject'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rubyfox-sfsobject
Usage
Bulk mode
require 'rubyfox/sfsobject/bulk'
sfs_object = Rubyfox::SFSObject::Bulk.to_sfs({ :hello => "world" })
# => SFSObject ready to use in SmartFox
hash = Rubyfox::SFSObject::Bulk.to_hash(sfs_object)
# => { :hello => "world" }
Schema mode
require 'rubyfox/sfsobject/schema'
schema = { :hello => String }
sfs_object = Rubyfox::SFSObject::Schema.to_sfs(schema, { :hello => "world" })
# => SFSObject ready to use in SmartFox
hash = Rubyfox::SFSObject::Schema.to_hash(schema, sfs_object)
# => { :hello => "world" }
Core extension
You can extend Hash and SFSObject with method shortcuts:
require 'rubyfox/sfsobject/core_ext'
sfs_object = { :hello => "world" }.to_sfs
# => SFSObject
sfs_object.to_hash
# { :hello => "world" }
JSON
require 'rubyfox/sfsobject/core_ext'
json = sfs_object.to_json
Rubyfox::SFSObject.from_json(json)
Hash-like access
require 'rubyfox/sfsobject/core_ext'
sfs_object = Rubyfox::SFSObject[:meaning_of_life => 42]
sfs_object[:meaning_of_life] # => 42
sfs_object[:string] = "value"
sfs_object[:string] # => "value"
Caveats
Note that all hash keys will be converted to symbols.
TODO
-
More docs, please!
Contributing
-
Fork it
-
Create your feature branch (‘git checkout -b my-new-feature`)
-
Commit your changes (‘git commit -am ’Add some feature’‘)
-
Push to the branch (‘git push origin my-new-feature`)
-
Create new Pull Request