ruby-xcdm 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +21 -0
- data/lib/xcdm/entity.rb +6 -1
- data/lib/xcdm/version.rb +1 -1
- data/test/entity_test.rb +16 -2
- data/test/fixtures/001_baseline.rb +2 -2
- data/test/fixtures/Article.xcdatamodeld/Article.xcdatamodel/contents +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d712f1fc465639fd48fdecf1348fd9ce08689fa
|
4
|
+
data.tar.gz: 216e010c595afbeefed2375f4dfce8e565a5b99d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c541e88501324879f89d3f55242591f82bdd548e0f57625931db4a8afb534aa2b291a5c2b345213d109c36aaa340abcd06614d4548ea396075f5a3e88cb6c612
|
7
|
+
data.tar.gz: f9b23caafabc23de2b59fa05b7a4c131fd7429c561996632752d0ea01d6e3d790a18c404e2062fc9f3f6620b78ed75f6a94ec457aa1121abf3cef92b7fccc651
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,8 @@ workflow and some niceties, like automatic inverse relationships.
|
|
10
10
|
[](https://travis-ci.org/infinitered/ruby-xcdm)
|
11
11
|
[](http://badge.fury.io/rb/ruby-xcdm)
|
12
12
|
|
13
|
+
ruby-xcdm is maintained by [Infinite Red](http://infinite.red), a web and mobile development company based in Portland, OR and San Francisco, CA.
|
14
|
+
|
13
15
|
## Installation
|
14
16
|
|
15
17
|
Add this line to your application's Gemfile:
|
@@ -164,6 +166,25 @@ You can also have symmetric one-to-one relationships via has_one:
|
|
164
166
|
end
|
165
167
|
```
|
166
168
|
|
169
|
+
Deletion rules can be easily set on relationships and the default rule is "Nullify":
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
entity "Discussion" do
|
173
|
+
has_many :messages, deletionRule: "Cascade"
|
174
|
+
end
|
175
|
+
|
176
|
+
entity "Message" do
|
177
|
+
belongs_to :discusion
|
178
|
+
end
|
179
|
+
|
180
|
+
# Example:
|
181
|
+
# Discussion.first.messages.count => 10
|
182
|
+
# Messages.count => 10
|
183
|
+
# Discussion.first.destroy
|
184
|
+
# cdq.save
|
185
|
+
# Messages.count => 0
|
186
|
+
```
|
187
|
+
|
167
188
|
Core Data has no equivalent of ```:through``` in ActiveRecord, so you'll
|
168
189
|
need to handle that relation yourself.
|
169
190
|
|
data/lib/xcdm/entity.rb
CHANGED
@@ -140,7 +140,12 @@ module XCDM
|
|
140
140
|
|
141
141
|
def to_xml(builder = nil)
|
142
142
|
builder ||= Builder::XmlMarkup.new(:indent => 2)
|
143
|
-
options = {
|
143
|
+
options = {
|
144
|
+
name: name,
|
145
|
+
syncable: 'YES',
|
146
|
+
representedClassName: class_name,
|
147
|
+
codeGenerationType: 'class'
|
148
|
+
}.merge(@options)
|
144
149
|
builder.entity(options) do |xml|
|
145
150
|
properties.each do |property|
|
146
151
|
xml.attribute(property)
|
data/lib/xcdm/version.rb
CHANGED
data/test/entity_test.rb
CHANGED
@@ -91,6 +91,13 @@ module XCDM
|
|
91
91
|
"Author", inverseName: "article", inverseEntity: "Author" }], e.relationships
|
92
92
|
end
|
93
93
|
|
94
|
+
def test_has_one_should_not_plural
|
95
|
+
e.has_one 'address'
|
96
|
+
assert_equal [{ optional: "YES", deletionRule: "Nullify", syncable: "YES",
|
97
|
+
name: "address", minCount: "1", maxCount: "1", destinationEntity:
|
98
|
+
"Address", inverseName: "article", inverseEntity: "Address" }], e.relationships
|
99
|
+
end
|
100
|
+
|
94
101
|
def test_belongs_to
|
95
102
|
e.belongs_to 'author'
|
96
103
|
assert_equal [{ optional: "YES", deletionRule: "Nullify", syncable: "YES",
|
@@ -105,6 +112,13 @@ module XCDM
|
|
105
112
|
"Author", inverseName: "article", inverseEntity: "Author" }], e.relationships
|
106
113
|
end
|
107
114
|
|
115
|
+
def test_deletion_cascade
|
116
|
+
e.has_many 'authors', { deletionRule: 'Cascade'}
|
117
|
+
assert_equal [{ optional: "YES", deletionRule: "Cascade", syncable: "YES",
|
118
|
+
name: "authors", minCount: "1", maxCount: "-1", destinationEntity:
|
119
|
+
"Author", inverseName: "article", inverseEntity: "Author" }], e.relationships
|
120
|
+
end
|
121
|
+
|
108
122
|
def test_non_inferrable_relationship_with_inverse
|
109
123
|
e.belongs_to 'primary_author', inverse: 'Author.primary_articles'
|
110
124
|
assert_equal [{ optional: "YES", deletionRule: "Nullify", syncable: "YES",
|
@@ -114,7 +128,7 @@ module XCDM
|
|
114
128
|
|
115
129
|
def test_to_xml
|
116
130
|
expected = REXML::Document.new %{
|
117
|
-
<entity name="Article" representedClassName="Article" parentEntity="Publication" syncable="YES">
|
131
|
+
<entity name="Article" codeGenerationType='class' representedClassName="Article" parentEntity="Publication" syncable="YES">
|
118
132
|
<attribute name="body" optional="NO" attributeType="String" syncable="YES"/>
|
119
133
|
<attribute name="length" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
|
120
134
|
<attribute name="published" optional="YES" attributeType="Boolean" defaultValueString="NO" syncable="YES"/>
|
@@ -135,7 +149,7 @@ module XCDM
|
|
135
149
|
assert_equal expected.to_s.strip, REXML::Document.new(e.to_xml).to_s.strip
|
136
150
|
|
137
151
|
expected = REXML::Document.new %{
|
138
|
-
<entity name="Publication" representedClassName="Publication" isAbstract="YES" syncable="YES">
|
152
|
+
<entity name="Publication" representedClassName="Publication" codeGenerationType='class' isAbstract="YES" syncable="YES">
|
139
153
|
</entity>
|
140
154
|
}
|
141
155
|
|
@@ -25,7 +25,7 @@ __END__
|
|
25
25
|
|
26
26
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
27
27
|
<model name="" userDefinedModelVersionIdentifier="0.0.1" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="2061" systemVersion="12D78" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
|
28
|
-
<entity name="Article" syncable="YES">
|
28
|
+
<entity name="Article" syncable="YES" codeGenerationType='class'>
|
29
29
|
<attribute name="body" optional="YES" attributeType="String" syncable="YES"/>
|
30
30
|
<attribute name="length" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
|
31
31
|
<attribute name="published" optional="YES" attributeType="Boolean" syncable="YES"/>
|
@@ -33,7 +33,7 @@ __END__
|
|
33
33
|
<attribute name="title" optional="YES" attributeType="String" syncable="YES"/>
|
34
34
|
<relationship name="author" optional="YES" minCount="1" maxCount="1" deletionRule="Nullify" destinationEntity="Author" inverseName="articles" inverseEntity="Article" syncable="YES"/>
|
35
35
|
</entity>
|
36
|
-
<entity name="Author" syncable="YES">
|
36
|
+
<entity name="Author" syncable="YES" codeGenerationType='class'>
|
37
37
|
<attribute name="fee" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES"/>
|
38
38
|
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
|
39
39
|
<relationship name="articles" optional="YES" minCount="1" maxCount="1" deletionRule="Nullify" destinationEntity="Article" inverseName="author" inverseEntity="Author" syncable="YES"/>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
2
|
<model name="" userDefinedModelVersionIdentifier="0.0.1" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="2061" systemVersion="12D78" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
|
3
|
-
<entity name="Article" representedClassName="Article" syncable="YES">
|
3
|
+
<entity codeGenerationType="class" name="Article" representedClassName="Article" syncable="YES">
|
4
4
|
<attribute name="body" optional="NO" attributeType="String" syncable="YES"/>
|
5
5
|
<attribute name="length" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
|
6
6
|
<attribute name="published" optional="YES" attributeType="Boolean" defaultValueString="NO" syncable="YES"/>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<attribute name="title" optional="NO" attributeType="String" syncable="YES"/>
|
9
9
|
<relationship name="author" optional="YES" minCount="1" maxCount="1" deletionRule="Nullify" destinationEntity="Author" inverseName="articles" inverseEntity="Author" syncable="YES"/>
|
10
10
|
</entity>
|
11
|
-
<entity name="Author" representedClassName="Author" syncable="YES">
|
11
|
+
<entity codeGenerationType="class" name="Author" representedClassName="Author" syncable="YES">
|
12
12
|
<attribute name="fee" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES"/>
|
13
13
|
<attribute name="name" optional="NO" attributeType="String" syncable="YES"/>
|
14
14
|
<relationship name="articles" optional="YES" minCount="1" maxCount="-1" deletionRule="Nullify" destinationEntity="Article" inverseName="author" inverseEntity="Article" syncable="YES"/>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-xcdm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Miller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: builder
|