ruby-xcdm 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ruby-xcdm.rb CHANGED
@@ -3,27 +3,31 @@ require 'xcdm/entity'
3
3
 
4
4
  if defined?(Motion::Project::Config)
5
5
 
6
- namespace :schema do
6
+ if File.directory?(File.join(App.config.project_dir, "schemas"))
7
+ namespace :schema do
7
8
 
8
- desc "Clear the datamodel outputs"
9
- task :clean do
10
- files = Dir.glob(File.join(App.config.project_dir, 'resources', App.config.name) + ".{momd,xcdatamodeld}")
11
- files.each do |f|
12
- rm_rf f
9
+ desc "Clear the datamodel outputs"
10
+ task :clean do
11
+ files = Dir.glob(File.join(App.config.project_dir, 'resources', App.config.name) + ".{momd,xcdatamodeld}")
12
+ files.each do |f|
13
+ rm_rf f
14
+ end
13
15
  end
14
- end
15
16
 
16
- desc "Generate the xcdatamodel file"
17
- task :build => :clean do
18
- Dir.chdir App.config.project_dir
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
+ desc "Generate the xcdatamodel file"
18
+ task :build => :clean do
19
+ Dir.chdir App.config.project_dir
20
+ if `xcodebuild -version` =~ /Xcode (\d.\d+)/
21
+ xcode_version = $1
22
+ else
23
+ raise "could not determine xcode version"
24
+ end
25
+ runner = XCDM::Schema::Runner.new( App.config.name, "schemas", "resources", App.config.sdk_version)
26
+ App.info "Generating", "Data Model #{App.config.name}"
27
+ runner.load_all { |schema, file| App.info "Loading", file }
28
+ runner.write_all { |schema, file| App.info "Writing", file }
29
+ end
23
30
  end
24
31
  end
25
32
 
26
- task :"build:simulator" => :"schema:build"
27
- task :"build:device" => :"schema:build"
28
-
29
33
  end
data/lib/xcdm/entity.rb CHANGED
@@ -27,7 +27,8 @@ module XCDM
27
27
  attr_reader :name, :properties, :relationships, :class_name
28
28
 
29
29
 
30
- def initialize(name, options = {})
30
+ def initialize(schema, name, options = {})
31
+ @schema = schema
31
32
  @name = name
32
33
  @class_name = options[:class_name] || name
33
34
  @properties = []
@@ -92,15 +93,33 @@ module XCDM
92
93
  end
93
94
 
94
95
  def belongs_to(name, options = {})
95
- relationship(name, {maxCount: 1, minCount: 1, plural_inverse: true}.merge(options))
96
+ case @schema.xcode_version
97
+ when /4\..*/
98
+ options = {maxCount: 1, minCount: 1, plural_inverse: true}.merge(options)
99
+ else
100
+ options = {maxCount: 1, plural_inverse: true}.merge(options)
101
+ end
102
+ relationship(name, options)
96
103
  end
97
104
 
98
105
  def has_one(name, options = {})
99
- relationship(name, {maxCount: 1, minCount: 1}.merge(options))
106
+ case @schema.xcode_version
107
+ when /4\..*/
108
+ options = {maxCount: 1, minCount: 1}.merge(options)
109
+ else
110
+ options = {maxCount: 1}.merge(options)
111
+ end
112
+ relationship(name, options)
100
113
  end
101
114
 
102
115
  def has_many(name, options = {})
103
- relationship(name, {maxCount: -1, minCount: 1}.merge(options))
116
+ case @schema.xcode_version
117
+ when /4\..*/
118
+ options = {maxCount: -1, minCount: 1}.merge(options)
119
+ else
120
+ options = {toMany: true}.merge(options)
121
+ end
122
+ relationship(name, options)
104
123
  end
105
124
 
106
125
 
data/lib/xcdm/schema.rb CHANGED
@@ -4,17 +4,19 @@ require 'fileutils'
4
4
  require 'plist'
5
5
 
6
6
  module XCDM
7
+
7
8
  class Schema
8
9
 
9
- attr_reader :version, :entities
10
+ attr_reader :version, :entities, :xcode_version
10
11
 
11
- def initialize(version)
12
+ def initialize(version, xcode_version)
12
13
  @version = version
14
+ @xcode_version = xcode_version
13
15
  @entities = []
14
16
  end
15
17
 
16
18
  def entity(name, options = {}, &block)
17
- @entities << Entity.new(name, options).tap { |e| e.instance_eval(&block) }
19
+ @entities << Entity.new(self, name, options).tap { |e| e.instance_eval(&block) }
18
20
  end
19
21
 
20
22
  def to_xml(builder = nil)
@@ -23,17 +25,31 @@ module XCDM
23
25
 
24
26
  builder.instruct! :xml, :standalone => 'yes'
25
27
 
26
- attrs = {
27
- name: "",
28
- userDefinedModelVersionIdentifier: version,
29
- type: "com.apple.IDECoreDataModeler.DataModel",
30
- documentVersion: "1.0",
31
- lastSavedToolsVersion: "2061",
32
- systemVersion: "12D78",
33
- minimumToolsVersion: "Xcode 4.3",
34
- macOSVersion: "Automatic",
35
- iOSVersion: "Automatic"
36
- }
28
+ if xcode_version =~ /5\.x/
29
+ attrs = {
30
+ name: "",
31
+ userDefinedModelVersionIdentifier: version,
32
+ type: "com.apple.IDECoreDataModeler.DataModel",
33
+ documentVersion: "1.0",
34
+ lastSavedToolsVersion: "3389",
35
+ systemVersion: "12E55",
36
+ minimumToolsVersion: "Xcode 5",
37
+ macOSVersion: "Automatic",
38
+ iOSVersion: "Automatic"
39
+ }
40
+ else
41
+ attrs = {
42
+ name: "",
43
+ userDefinedModelVersionIdentifier: version,
44
+ type: "com.apple.IDECoreDataModeler.DataModel",
45
+ documentVersion: "1.0",
46
+ lastSavedToolsVersion: "2061",
47
+ systemVersion: "12D78",
48
+ minimumToolsVersion: "Xcode 4.3",
49
+ macOSVersion: "Automatic",
50
+ iOSVersion: "Automatic"
51
+ }
52
+ end
37
53
 
38
54
  builder.model(attrs) do |builder|
39
55
  entities.each do |entity|
@@ -45,13 +61,15 @@ module XCDM
45
61
  class Loader
46
62
 
47
63
  attr_reader :schemas
64
+ attr_reader :xcode_version
48
65
 
49
- def initialize
66
+ def initialize(xcode_version)
67
+ @xcode_version = xcode_version
50
68
  @schemas = []
51
69
  end
52
70
 
53
71
  def schema(version, &block)
54
- @found_schema = Schema.new(version).tap { |s| s.instance_eval(&block) }
72
+ @found_schema = Schema.new(version, xcode_version).tap { |s| s.instance_eval(&block) }
55
73
  @schemas << @found_schema
56
74
  end
57
75
 
@@ -65,11 +83,11 @@ module XCDM
65
83
  end
66
84
 
67
85
  class Runner
68
- def initialize(name, inpath, outpath)
86
+ def initialize(name, inpath, outpath, xcode_version)
69
87
  @inpath = inpath
70
88
  @name = name
71
89
  @container_path = File.join(outpath, "#{name}.xcdatamodeld")
72
- @loader = Loader.new
90
+ @loader = Loader.new(xcode_version)
73
91
  end
74
92
 
75
93
  def datamodel_file(version)
data/lib/xcdm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module XCDM
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/test/entity_test.rb CHANGED
@@ -8,7 +8,8 @@ module XCDM
8
8
  class EntityTest < Test::Unit::TestCase
9
9
 
10
10
  def e
11
- @e ||= Entity.new("Article")
11
+ s = Schema.new("0.0.1", "4.6")
12
+ @e ||= Entity.new(s, "Article")
12
13
  end
13
14
 
14
15
  def test_initialize
data/test/schema_test.rb CHANGED
@@ -8,12 +8,13 @@ module XCDM
8
8
  class SchemaTest < Test::Unit::TestCase
9
9
 
10
10
  def test_initialize
11
- s = Schema.new("0.0.1")
11
+ s = Schema.new("0.0.1", "4.6")
12
12
  assert_equal "0.0.1", s.version
13
+ assert_equal "4.6", s.xcode_version
13
14
  end
14
15
 
15
16
  def test_entity
16
- s = Schema.new("0.0.1")
17
+ s = Schema.new("0.0.1", "4.6")
17
18
  entity = nil
18
19
  s.entity("MyType") { entity = self; nil }
19
20
  assert entity.is_a?(Entity), "Block should be executed in context of the new entity"
@@ -23,7 +24,7 @@ module XCDM
23
24
  def test_loader
24
25
  fixture = File.join(File.dirname(__FILE__), 'fixtures', '001_baseline.rb')
25
26
 
26
- loader = Schema::Loader.new
27
+ loader = Schema::Loader.new("4.6")
27
28
  schema = loader.load_file(fixture)
28
29
  assert_not_nil schema
29
30
  assert_equal '0.0.1', schema.version
@@ -33,7 +34,7 @@ module XCDM
33
34
 
34
35
  def test_to_xml
35
36
  in_fixture = File.join(File.dirname(__FILE__), 'fixtures', '001_baseline.rb')
36
- loader = Schema::Loader.new
37
+ loader = Schema::Loader.new("4.6")
37
38
  schema = loader.load_file(in_fixture)
38
39
 
39
40
  out_fixture = File.join(File.dirname(__FILE__), 'fixtures', 'Article.xcdatamodeld', 'Article.xcdatamodel', 'contents')
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.3
4
+ version: 0.0.4
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-18 00:00:00.000000000 Z
12
+ date: 2013-08-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
@@ -134,7 +134,6 @@ files:
134
134
  - test/fixtures/001_baseline.rb
135
135
  - test/fixtures/Article.xcdatamodeld/Article.xcdatamodel/contents
136
136
  - test/schema_test.rb
137
- - test/test_schema.rb
138
137
  homepage: https://github.com/infinitered/ruby-xcdm
139
138
  licenses:
140
139
  - MIT
@@ -165,4 +164,3 @@ test_files:
165
164
  - test/fixtures/001_baseline.rb
166
165
  - test/fixtures/Article.xcdatamodeld/Article.xcdatamodel/contents
167
166
  - test/schema_test.rb
168
- - test/test_schema.rb
data/test/test_schema.rb DELETED
@@ -1,19 +0,0 @@
1
-
2
- require 'test/unit'
3
- require 'schema'
4
-
5
- class SchemaTest < Test::Unit::TestCase
6
-
7
- def test_initialize
8
- s = Schema.new("0.0.1")
9
- assert_equal "0.0.1", s.version
10
- end
11
-
12
- def test_entity
13
- s = Schema.new("0.0.1")
14
- e = s.entity("MyType") { |e| assert e.is_a?(Entity) }
15
- assert e.is_a?(Entity)
16
- end
17
-
18
-
19
- end