ruby-xcdm 0.0.2 → 0.0.3
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.
- data/Rakefile +2 -0
- data/lib/ruby-xcdm.rb +7 -7
- data/lib/xcdm/entity.rb +3 -2
- data/lib/xcdm/schema.rb +7 -7
- data/lib/xcdm/version.rb +1 -1
- data/test/entity_test.rb +1 -1
- data/test/fixtures/Article.xcdatamodeld/Article.xcdatamodel/contents +2 -2
- metadata +2 -2
data/Rakefile
CHANGED
data/lib/ruby-xcdm.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'xcdm/schema'
|
2
|
+
require 'xcdm/entity'
|
3
|
+
|
1
4
|
if defined?(Motion::Project::Config)
|
2
5
|
|
3
6
|
namespace :schema do
|
@@ -13,17 +16,14 @@ if defined?(Motion::Project::Config)
|
|
13
16
|
desc "Generate the xcdatamodel file"
|
14
17
|
task :build => :clean do
|
15
18
|
Dir.chdir App.config.project_dir
|
16
|
-
|
19
|
+
runner = XCDM::Schema::Runner.new( App.config.name, "schemas", "resources")
|
20
|
+
App.info "Generating", "Data Model #{App.config.name}"
|
21
|
+
runner.load_all { |schema, file| App.info "Loading", file }
|
22
|
+
runner.write_all { |schema, file| App.info "Writing", file }
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
20
26
|
task :"build:simulator" => :"schema:build"
|
21
27
|
task :"build:device" => :"schema:build"
|
22
28
|
|
23
|
-
|
24
|
-
else
|
25
|
-
|
26
|
-
require 'xcdm/schema'
|
27
|
-
require 'xcdm/entity'
|
28
|
-
|
29
29
|
end
|
data/lib/xcdm/entity.rb
CHANGED
@@ -24,11 +24,12 @@ module XCDM
|
|
24
24
|
}
|
25
25
|
|
26
26
|
|
27
|
-
attr_reader :name, :properties, :relationships
|
27
|
+
attr_reader :name, :properties, :relationships, :class_name
|
28
28
|
|
29
29
|
|
30
30
|
def initialize(name, options = {})
|
31
31
|
@name = name
|
32
|
+
@class_name = options[:class_name] || name
|
32
33
|
@properties = []
|
33
34
|
@relationships = []
|
34
35
|
end
|
@@ -109,7 +110,7 @@ module XCDM
|
|
109
110
|
|
110
111
|
def to_xml(builder = nil)
|
111
112
|
builder ||= Builder::XmlMarkup.new(:indent => 2)
|
112
|
-
builder.entity(name: name, syncable: 'YES') do |xml|
|
113
|
+
builder.entity(name: name, syncable: 'YES', representedClassName: class_name ) do |xml|
|
113
114
|
properties.each do |property|
|
114
115
|
xml.attribute(property)
|
115
116
|
end
|
data/lib/xcdm/schema.rb
CHANGED
@@ -13,8 +13,8 @@ module XCDM
|
|
13
13
|
@entities = []
|
14
14
|
end
|
15
15
|
|
16
|
-
def entity(name, &block)
|
17
|
-
@entities << Entity.new(name).tap { |e| e.instance_eval(&block) }
|
16
|
+
def entity(name, options = {}, &block)
|
17
|
+
@entities << Entity.new(name, options).tap { |e| e.instance_eval(&block) }
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_xml(builder = nil)
|
@@ -78,19 +78,19 @@ module XCDM
|
|
78
78
|
File.join(dir, 'contents')
|
79
79
|
end
|
80
80
|
|
81
|
-
def load_all
|
81
|
+
def load_all(&block)
|
82
82
|
Dir["#{@inpath}/*.rb"].each do |file|
|
83
83
|
if File.file?(file)
|
84
|
-
|
85
|
-
|
84
|
+
schema = @loader.load_file(file)
|
85
|
+
block.call(schema, file) if block_given?
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
def write_all
|
90
|
+
def write_all(&block)
|
91
91
|
@loader.schemas.each do |schema|
|
92
92
|
filename = datamodel_file(schema.version)
|
93
|
-
|
93
|
+
block.call(schema, filename) if block_given?
|
94
94
|
File.open(filename, "w+") do |f|
|
95
95
|
f.write(schema.to_xml)
|
96
96
|
end
|
data/lib/xcdm/version.rb
CHANGED
data/test/entity_test.rb
CHANGED
@@ -98,7 +98,7 @@ module XCDM
|
|
98
98
|
|
99
99
|
def test_to_xml
|
100
100
|
expected = REXML::Document.new %{
|
101
|
-
<entity name="Article" syncable="YES">
|
101
|
+
<entity name="Article" representedClassName="Article" syncable="YES">
|
102
102
|
<attribute name="body" optional="NO" attributeType="String" syncable="YES"/>
|
103
103
|
<attribute name="length" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
|
104
104
|
<attribute name="published" optional="YES" attributeType="Boolean" defaultValueString="NO" 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" syncable="YES">
|
3
|
+
<entity 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" syncable="YES">
|
11
|
+
<entity 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,7 +1,7 @@
|
|
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|