README.markdown in blobject-0.3.3 vs README.markdown in blobject-0.3.7
- old
+ new
@@ -1,40 +1,76 @@
-![](https://github.com/sjltaylor/blobject/raw/master/blobject.png)
-![](https://github.com/sjltaylor/blobject/raw/master/blob_defn.png)
+![](https://github.com/sjltaylor/blobject/raw/master/assets/blobject.png)
+![](https://github.com/sjltaylor/blobject/raw/master/assets/blob_defn.png)
-Data structures which __just work__
+Getting started: `http://sjltaylor.com/blobject'
## About
-A Blobject is a thin wrapper around a hash
+Blobjects are *freeform* which means you can do this...
-
-They are *freeform* which means you can do this...
-
data = Blobject.new
data.name = "Johnny"
data.number = 316
-like an OpenStruct, the members are not predefined attributes
+like an `OpenStruct`, the members are not predefined attributes
-unlike OpenStruct, Blobjects can be arbitrarily *complex* which means you can do this...
+unlike `OpenStruct`, `Blobject`s can be arbitrarily *complex* which means you can do this...
data = Blobject.new
+ => {}
data.name.first = "Johnny"
data.name.surname = "Begood"
+ => {:name=>{:first=>"Johnny", :surname=>"Begood"}}
data.my.object.with.deep.nested.members = "happy place"
+ => {:name=>{:first=>"Johnny", :surname=>"Begood"}, :my=>{:object=>{:with=>{:deep=>{:nested=>{:members=>"happy place"}}}}}}
+You can assign hashes which become nested blobjects
+
+ data.details = { code: 41239, ref: "#22322" }
+
+ data.details.code
+ => 41239
+ data.details.code = 11322
+ data.details.code
+ => 11322
+ data.details.ref
+ => "#22322"
+
+
You can test to see if a member is defined:
data.something_here?
=> false
+ data.name?
+ => true
+You can use it like a hash
+ data[:name]
+ => {:first=>"Johnny", :surname=>"Begood"}
+ data[:name][:first] = "Jimmy"; data[:name]
+ => {:first=>"Jimmy", :surname=>"Begood"}
+
+ data.empty?
+ => false
+
+ data.name == {:first=>"Jimmy", :surname=>"Begood"}
+ => true
+
+You can get access to the internal hash with `Blobject#hash` or a de-blobjectified copy with `Blobject#to_hash`
+
+You can call `Blobject#freeze` to prevent the data being modified. This still allows chained calls: `blobject.data.nested.is_something_here?` but assignments will raise `RuntimeError: can't modify frozen Hash`
+
+You can work with JSON data using `Blobject.from_json` and `Blobject#to_json`, in Rails, you can use `Blobject#as_json` as you would with a hash.
+
+You can work with YAML data using `Blobject.from_yaml` and `Blobject#to_yaml`.
+
+
## Used for Configuration
Consider a configuration object which contains credentials for a third-party api.
third_party_api:
@@ -66,11 +102,11 @@
"#{protocol}://#{hostname}#{path}"
end
end
-## Serialization
+## Serializing & Deserializing
Blobjects can be used to easily build complex payloads.
person = Blobject.new
@@ -91,13 +127,10 @@
Blobject.new optional_hash_of_initial_data do |b|
b.name = ...
end.freeze
-## Deserialization
-
-
Suppose you receive a payload from an api which may or may not contain an address and city...
payload = Blobject.from_json request[:payload]
# if the payload does have an address...
@@ -153,5 +186,26 @@
* will not work with basic objects unless #class and #freeze are implemented
* cyclic blobject graphs result in infinite recursion StackOverflow
* Ruby 1.8.7 is not supported. Testing rubies...
* mri 1.9.3-p194
* mri 1.9.2-p290
+
+
+## Disclaimer
+
+Blobject provides a convenient way to create large freeform data structures; With great power comes great blah blah blah blah...
+
+
+## License
+
+(The MIT License)
+
+Copyright © 2012 [Sam Taylor](http://sjltaylor.com/)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Copyright (c) 2012 Sam Taylor. See LICENSE.txt for
+further details.