blobject 0.3.3 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
+ .yardoc
3
4
  pkg/*
4
5
  TODO
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blobject (0.3.3)
4
+ blobject (0.3.6)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.markdown CHANGED
@@ -1,36 +1,72 @@
1
- ![](https://github.com/sjltaylor/blobject/raw/master/blobject.png)
2
- ![](https://github.com/sjltaylor/blobject/raw/master/blob_defn.png)
1
+ ![](https://github.com/sjltaylor/blobject/raw/master/assets/blobject.png)
2
+ ![](https://github.com/sjltaylor/blobject/raw/master/assets/blob_defn.png)
3
3
 
4
- Data structures which __just work__
4
+ Getting started: `http://sjltaylor.com/blobject'
5
5
 
6
6
  ## About
7
7
 
8
- A Blobject is a thin wrapper around a hash
9
-
10
-
11
- They are *freeform* which means you can do this...
8
+ Blobjects are *freeform* which means you can do this...
12
9
 
13
10
  data = Blobject.new
14
11
 
15
12
  data.name = "Johnny"
16
13
  data.number = 316
17
14
 
18
- like an OpenStruct, the members are not predefined attributes
15
+ like an `OpenStruct`, the members are not predefined attributes
19
16
 
20
- unlike OpenStruct, Blobjects can be arbitrarily *complex* which means you can do this...
17
+ unlike `OpenStruct`, `Blobject`s can be arbitrarily *complex* which means you can do this...
21
18
 
22
19
  data = Blobject.new
20
+ => {}
23
21
 
24
22
  data.name.first = "Johnny"
25
23
  data.name.surname = "Begood"
24
+ => {:name=>{:first=>"Johnny", :surname=>"Begood"}}
26
25
 
27
26
  data.my.object.with.deep.nested.members = "happy place"
27
+ => {:name=>{:first=>"Johnny", :surname=>"Begood"}, :my=>{:object=>{:with=>{:deep=>{:nested=>{:members=>"happy place"}}}}}}
28
+
29
+ You can assign hashes which become nested blobjects
30
+
31
+ data.details = { code: 41239, ref: "#22322" }
32
+
33
+ data.details.code
34
+ => 41239
35
+ data.details.code = 11322
36
+ data.details.code
37
+ => 11322
38
+ data.details.ref
39
+ => "#22322"
40
+
28
41
 
29
42
  You can test to see if a member is defined:
30
43
 
31
44
  data.something_here?
32
45
  => false
46
+ data.name?
47
+ => true
48
+
49
+ You can use it like a hash
50
+
51
+ data[:name]
52
+ => {:first=>"Johnny", :surname=>"Begood"}
53
+
54
+ data[:name][:first] = "Jimmy"; data[:name]
55
+ => {:first=>"Jimmy", :surname=>"Begood"}
56
+
57
+ data.empty?
58
+ => false
59
+
60
+ data.name == {:first=>"Jimmy", :surname=>"Begood"}
61
+ => true
62
+
63
+ You can get access to the internal hash with `Blobject#hash` or a de-blobjectified copy with `Blobject#to_hash`
64
+
65
+ 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`
33
66
 
67
+ 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.
68
+
69
+ You can work with YAML data using `Blobject.from_yaml` and `Blobject#to_yaml`.
34
70
 
35
71
 
36
72
  ## Used for Configuration
@@ -68,7 +104,7 @@ Using a blobject we can easily avoid having to refactor our code...
68
104
  end
69
105
 
70
106
 
71
- ## Serialization
107
+ ## Serializing & Deserializing
72
108
 
73
109
  Blobjects can be used to easily build complex payloads.
74
110
 
@@ -93,9 +129,6 @@ A nice pattern in most cases is to use an initialization block...
93
129
  end.freeze
94
130
 
95
131
 
96
- ## Deserialization
97
-
98
-
99
132
  Suppose you receive a payload from an api which may or may not contain an address and city...
100
133
 
101
134
  payload = Blobject.from_json request[:payload]
@@ -155,3 +188,24 @@ A Blobject is three-four times slower than an equivalent Object.
155
188
  * Ruby 1.8.7 is not supported. Testing rubies...
156
189
  * mri 1.9.3-p194
157
190
  * mri 1.9.2-p290
191
+
192
+
193
+ ## Disclaimer
194
+
195
+ Blobject provides a convenient way to create large freeform data structures; With great power comes great blah blah blah blah...
196
+
197
+
198
+ ## License
199
+
200
+ (The MIT License)
201
+
202
+ Copyright © 2012 [Sam Taylor](http://sjltaylor.com/)
203
+
204
+ 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:
205
+
206
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
207
+
208
+ 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.
209
+
210
+ Copyright (c) 2012 Sam Taylor. See LICENSE.txt for
211
+ further details.
File without changes
File without changes