structure 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -2,3 +2,12 @@
2
2
 
3
3
  * Make JSON patch compatible with Active Support.
4
4
  * Remove URI from list of types.
5
+
6
+ # 0.9
7
+
8
+ * Add presence method.
9
+
10
+ # 0.10
11
+
12
+ * Rename has_one and has_many to embeds_one and embeds_many to make room
13
+ for associations.
data/README.md CHANGED
@@ -1,12 +1,9 @@
1
1
  Structure
2
2
  =========
3
3
 
4
- Structure is a Struct-like key/value container for modeling ephemeral data in
5
- Ruby.
4
+ Structure is a key/value container for modeling ephemeral data in Ruby.
6
5
 
7
- Structure typecasts, uses basic association idioms, and converts to and from
8
- JSON seamlessly, even when nested in structures or other structure-like
9
- objects.
6
+ Structure typecasts, nests other structures, and talks flawless JSON.
10
7
 
11
8
  #_ d
12
9
  ##_ d#
@@ -34,73 +31,83 @@ objects.
34
31
  Usage
35
32
  -----
36
33
 
37
- Require:
38
-
39
- require 'structure'
40
-
41
34
  Define a model:
42
35
 
43
- class Person < Structure
44
- key :name
45
- key :age, :type => Integer
46
- has_many :friends
47
- has_one :partner
48
- end
36
+ ```ruby
37
+ require 'structure'
38
+
39
+ class Person < Structure
40
+ key :name
41
+ key :age, :type => Integer
42
+ has_many :friends
43
+ has_one :partner
44
+ end
45
+ ```
49
46
 
50
47
  Conjure an object:
51
48
 
52
- p1 = Person.new :name => 'Gilles'
49
+ ```ruby
50
+ p1 = Person.new :name => 'Gilles'
51
+ ```
53
52
 
54
53
  Typecast:
55
54
 
56
- p1.age = '28'
57
- p1.age
58
- => 28
55
+ ```ruby
56
+ p1.age = '28'
57
+ p1.age
58
+ => 28
59
+ ```
59
60
 
60
61
  Check for presence:
61
- p1.age?
62
- => true
63
62
 
64
- Embed other structures:
63
+ ```ruby
64
+ p1.age?
65
+ => true
66
+ ```
65
67
 
66
- p2 = Person.new
67
- p1.friends << p2
68
68
 
69
- Dump well-structured JSON:
69
+ Embed other structures:
70
70
 
71
- require 'structure/json'
71
+ ```ruby
72
+ p2 = Person.new
73
+ p1.friends << p2
74
+ ```
72
75
 
73
- json = p1.to_json
74
- => {"json_class":"Person","name":"John","age":28,"friends":[{"json_class":"Person","name":null,"age":null,"friends":[]}],"partner":null}
76
+ Talk JSON:
75
77
 
76
- Load the JSON seamlessly back into Ruby:
78
+ ```ruby
79
+ require 'structure/json'
77
80
 
78
- person = JSON.parse(json)
79
- person.friends.first
80
- => #<Person:0x0000010107d030 @attributes={:name=>nil, :age=>nil, :friends=>[], :partner=>nil}>
81
+ json = p1.to_json
82
+ => {"json_class":"Person","name":"John","age":28,"friends":[{"json_class":"Person","name":null,"age":null,"friends":[]}],"partner":null}
81
83
 
82
- Throw in some Active Model modules:
84
+ person = JSON.parse(json)
85
+ person.friends.first
86
+ => #<Person:0x0000010107d030 @attributes={:name=>nil, :age=>nil, :friends=>[], :partner=>nil}>
87
+ ```
83
88
 
84
- require 'active_model'
89
+ Quack Active Model:
85
90
 
86
- class Book < Structure
87
- include ActiveModel::Validations
91
+ ```ruby
92
+ require 'active_model'
88
93
 
89
- key :title
94
+ class Book < Structure
95
+ include ActiveModel::Validations
90
96
 
91
- validates_presence_of :title
92
- end
97
+ key :title
93
98
 
94
- ... and make your model quack like ActiveRecord:
99
+ validates_presence_of :title
100
+ end
95
101
 
96
- book = Book.new
97
- book.valid?
98
- => false
99
- book.errors
100
- => {:title=>["can't be blank"]}
101
- book.title = "Society of the Spectacle"
102
- book.valid?
103
- => true
102
+ book = Book.new
103
+ book.valid?
104
+ => false
105
+ book.errors
106
+ => {:title=>["can't be blank"]}
107
+ book.title = "Society of the Spectacle"
108
+ book.valid?
109
+ => true
110
+ ```
104
111
 
105
112
  Types
106
113
  -----
data/lib/structure.rb CHANGED
@@ -15,12 +15,12 @@ class Structure
15
15
 
16
16
  # A shortcut to define an attribute that represents an array of other
17
17
  # objects, possibly structures.
18
- def has_many(name)
18
+ def embeds_many(name)
19
19
  key name, :type => Array, :default => []
20
20
  end
21
21
 
22
22
  # A shortcut to define an attribute that represents another structure.
23
- def has_one(name)
23
+ def embeds_one(name)
24
24
  key name, :type => Structure
25
25
  end
26
26
 
@@ -1,3 +1,3 @@
1
1
  class Structure
2
- VERSION = '0.9.0'
2
+ VERSION = '0.10.0'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  class Person < Structure
2
2
  key :name
3
3
  key :age, :type => Integer
4
- has_many :friends
4
+ embeds_many :friends
5
5
  end
@@ -154,7 +154,7 @@ describe Structure do
154
154
 
155
155
  context "when type is Structure" do
156
156
  before(:all) do
157
- Person.has_one :father
157
+ Person.embeds_one :father
158
158
  end
159
159
 
160
160
  context "when setting to a value that is not a Structure" do
data/structure.gemspec CHANGED
@@ -9,10 +9,9 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Paper Cavalier"]
10
10
  s.email = ["code@papercavalier.com"]
11
11
  s.homepage = "http://rubygems.com/gems/structure"
12
- s.summary = "Struct-like key/value container in Ruby"
12
+ s.summary = "A key/value container for modeling ephemeral data"
13
13
  s.description = <<-END_OF_DESCRIPTION.strip
14
- Structure is a Struct-like key/value container for modeling ephemeral data
15
- in Ruby.
14
+ Structure is a key/value container for modeling ephemeral data.
16
15
  END_OF_DESCRIPTION
17
16
 
18
17
  s.rubyforge_project = "structure"
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 9
7
+ - 10
8
8
  - 0
9
- version: 0.9.0
9
+ version: 0.10.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Paper Cavalier
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-06-29 00:00:00 +01:00
17
+ date: 2011-07-05 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -60,9 +60,7 @@ dependencies:
60
60
  version: 0.11.6
61
61
  type: :development
62
62
  version_requirements: *id003
63
- description: |-
64
- Structure is a Struct-like key/value container for modeling ephemeral data
65
- in Ruby.
63
+ description: Structure is a key/value container for modeling ephemeral data.
66
64
  email:
67
65
  - code@papercavalier.com
68
66
  executables: []
@@ -120,7 +118,7 @@ rubyforge_project: structure
120
118
  rubygems_version: 1.3.7
121
119
  signing_key:
122
120
  specification_version: 3
123
- summary: Struct-like key/value container in Ruby
121
+ summary: A key/value container for modeling ephemeral data
124
122
  test_files:
125
123
  - spec/models/book.rb
126
124
  - spec/models/person.rb