blobject 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +125 -0
- data/blobject.gemspec +3 -3
- data/blobject.png +0 -0
- data/blobject.psd +0 -0
- data/lib/blobject/version.rb +1 -1
- metadata +8 -6
- data/README.rdoc +0 -43
data/README.markdown
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
![](https://github.com/sjltaylor/blobject/raw/master/blobject.png)
|
2
|
+
|
3
|
+
Provides a free flowing syntax for creating blobs of data.
|
4
|
+
|
5
|
+
## Examples
|
6
|
+
|
7
|
+
### Creating a Blobject
|
8
|
+
|
9
|
+
#### Basic usage
|
10
|
+
b = Blobject.new
|
11
|
+
|
12
|
+
b.name.first = 'Rick'
|
13
|
+
b.name.last = 'Astley'
|
14
|
+
|
15
|
+
b.url = 'http://www.youtube.com/watch?v=dQw4w9WgXcQ'
|
16
|
+
|
17
|
+
#### With a block
|
18
|
+
b = Blobject.new do |b|
|
19
|
+
|
20
|
+
b.name.first = 'Rick'
|
21
|
+
b.name.last = 'Astley'
|
22
|
+
|
23
|
+
b.url = 'http://www.youtube.com/watch?v=dQw4w9WgXcQ'
|
24
|
+
end
|
25
|
+
|
26
|
+
#### With a hash
|
27
|
+
b = Blobject.new :name => {:first => 'Rick', :last => 'Astley'}, :url => 'http://www.youtube.com/watch?v=dQw4w9WgXcQ'
|
28
|
+
|
29
|
+
#### With selected members of an existing object
|
30
|
+
b = Blobject.new existing_object, [:name, :url]
|
31
|
+
|
32
|
+
#### With the global shortcut method
|
33
|
+
b = blobject do |b|
|
34
|
+
b.name.first = 'Rick'
|
35
|
+
b.name.last = 'Astley'
|
36
|
+
|
37
|
+
b.url = 'http://www.youtube.com/watch?v=dQw4w9WgXcQ'
|
38
|
+
end
|
39
|
+
|
40
|
+
all of the above initialisation methods can be used in this way too.
|
41
|
+
|
42
|
+
### Object graphs can be as complex as necessary
|
43
|
+
b = blobject
|
44
|
+
b.very.deep.nesting.of.objects = 2
|
45
|
+
|
46
|
+
The intermediary blobjects are created automagically
|
47
|
+
|
48
|
+
### Check for the existence of a member
|
49
|
+
b = blobject
|
50
|
+
b.name = 'Rick'
|
51
|
+
b.url?
|
52
|
+
=> false
|
53
|
+
b.name?
|
54
|
+
=> true
|
55
|
+
|
56
|
+
### Overrides ruby freeze and unfreeze
|
57
|
+
The freeze method prevents the blobject from being extended or changed.
|
58
|
+
|
59
|
+
b = blobject do |b|
|
60
|
+
b.name.first = 'Rick'
|
61
|
+
b.name.last = 'Astley'
|
62
|
+
|
63
|
+
b.url = 'http://www.youtube.com/watch?v=dQw4w9WgXcQ'
|
64
|
+
end.freeze
|
65
|
+
b.frozen?
|
66
|
+
=> true
|
67
|
+
b.am_i_here
|
68
|
+
=> nil
|
69
|
+
b.name?
|
70
|
+
=> true
|
71
|
+
b.name = 'hello'
|
72
|
+
=> Exception!
|
73
|
+
|
74
|
+
### `empty?` and `blank?`
|
75
|
+
b = blobject
|
76
|
+
b.empty? && b.blank?
|
77
|
+
=> true
|
78
|
+
b.number = 123
|
79
|
+
b.empty? || b.blank?
|
80
|
+
=> false
|
81
|
+
|
82
|
+
## Feature summary
|
83
|
+
|
84
|
+
* call a chain of methods and build an object graph automagically
|
85
|
+
* check the existence of a member with 'method?'
|
86
|
+
* overrides ruby freeze
|
87
|
+
* recursively parses blobjects from json strings
|
88
|
+
* can be initialized with...
|
89
|
+
** an object and list of accessors to copy
|
90
|
+
** a hash
|
91
|
+
** a block
|
92
|
+
|
93
|
+
## Intended usage and limitations
|
94
|
+
|
95
|
+
Intended for use to create view models which can be encoded to JSON with ActiveSupport::JSON.encode
|
96
|
+
JSON can be unmarshalled into a blobject (recursively) with `Blobject.from_json json_string`
|
97
|
+
|
98
|
+
Blobjects are intended for de/serialization, therefore cycles in the object graph will lead to a non terminating thread.
|
99
|
+
|
100
|
+
|
101
|
+
## Contributing to blobject
|
102
|
+
|
103
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
104
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
105
|
+
* Fork the project
|
106
|
+
* Start a feature/bugfix branch
|
107
|
+
* Commit and push until you are happy with your contribution
|
108
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
109
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
110
|
+
|
111
|
+
## License
|
112
|
+
|
113
|
+
(The MIT License)
|
114
|
+
|
115
|
+
Copyright © 2011 [Sam Taylor](http://sjltaylor.com/)
|
116
|
+
|
117
|
+
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:
|
118
|
+
|
119
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
120
|
+
|
121
|
+
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.
|
122
|
+
|
123
|
+
Copyright (c) 2011 Sam Taylor. See LICENSE.txt for
|
124
|
+
further details.
|
125
|
+
|
data/blobject.gemspec
CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Sam Taylor"]
|
10
10
|
s.email = ["sjltaylor@gmail.com"]
|
11
|
-
s.homepage = "
|
12
|
-
s.summary = %q{
|
13
|
-
|
11
|
+
s.homepage = "https://github.com/sjltaylor/blobject"
|
12
|
+
s.summary = %q{serializable object builder}
|
13
|
+
s.description = %q{Blobject provides a free flowing syntax for creating blobs of data.}
|
14
14
|
|
15
15
|
s.rubyforge_project = "blobject"
|
16
16
|
|
data/blobject.png
ADDED
Binary file
|
data/blobject.psd
ADDED
Binary file
|
data/lib/blobject/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: blobject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sam Taylor
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-14 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -35,7 +35,7 @@ dependencies:
|
|
35
35
|
version: "0"
|
36
36
|
type: :runtime
|
37
37
|
version_requirements: *id002
|
38
|
-
description:
|
38
|
+
description: Blobject provides a free flowing syntax for creating blobs of data.
|
39
39
|
email:
|
40
40
|
- sjltaylor@gmail.com
|
41
41
|
executables: []
|
@@ -47,15 +47,17 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- .gitignore
|
49
49
|
- Gemfile
|
50
|
-
- README.
|
50
|
+
- README.markdown
|
51
51
|
- Rakefile
|
52
52
|
- blobject.gemspec
|
53
|
+
- blobject.png
|
54
|
+
- blobject.psd
|
53
55
|
- lib/blobject.rb
|
54
56
|
- lib/blobject/version.rb
|
55
57
|
- test/helper.rb
|
56
58
|
- test/test_blobject.rb
|
57
59
|
has_rdoc: true
|
58
|
-
homepage:
|
60
|
+
homepage: https://github.com/sjltaylor/blobject
|
59
61
|
licenses: []
|
60
62
|
|
61
63
|
post_install_message:
|
@@ -81,7 +83,7 @@ rubyforge_project: blobject
|
|
81
83
|
rubygems_version: 1.5.0
|
82
84
|
signing_key:
|
83
85
|
specification_version: 3
|
84
|
-
summary:
|
86
|
+
summary: serializable object builder
|
85
87
|
test_files:
|
86
88
|
- test/helper.rb
|
87
89
|
- test/test_blobject.rb
|
data/README.rdoc
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
= blobject
|
2
|
-
|
3
|
-
Blobject is for building untyped blobs of data.
|
4
|
-
|
5
|
-
An ActiveRecord is not usually enough for view data. The required view data could be more than on ActiveRecords and/or the resultant calculations of some business logic.
|
6
|
-
|
7
|
-
= Features
|
8
|
-
|
9
|
-
* call a chain of methods and build an object graph automagically
|
10
|
-
* check the existence of a value with 'method?'
|
11
|
-
* overrides ruby freeze
|
12
|
-
* recursively loads data from JSON strings
|
13
|
-
* empty? recursive
|
14
|
-
|
15
|
-
* init with an object and list of accessors to copy
|
16
|
-
* init with hash
|
17
|
-
* init with block (frozen)
|
18
|
-
|
19
|
-
|
20
|
-
= Example Usage
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
= Limitations
|
25
|
-
|
26
|
-
Blobjects are intended for de/serialization and there for the cycles in the object graph will lead to a non terminating thread.
|
27
|
-
|
28
|
-
|
29
|
-
== Contributing to blobject
|
30
|
-
|
31
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
32
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
33
|
-
* Fork the project
|
34
|
-
* Start a feature/bugfix branch
|
35
|
-
* Commit and push until you are happy with your contribution
|
36
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
37
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
38
|
-
|
39
|
-
== Copyright
|
40
|
-
|
41
|
-
Copyright (c) 2011 Sam Taylor. See LICENSE.txt for
|
42
|
-
further details.
|
43
|
-
|