ruby-xcdm 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Zjc5N2MxNzBmNWIwOTNkYzdjMzc4YmEyYzVmMDI3M2YwOGUxZWZkMA==
5
+ data.tar.gz: !binary |-
6
+ ODFhYmNjZDE0OTBkNWE4OTk5YzJkMGQ1OWU1NjAyYmM0ZWU4ZWY4Nw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZTQxNTQwNzhjMzQ1OTkyNzljYzY5ZjgxYzJkOWM3YTgzYTIwNzVjN2YzNjU0
10
+ MzcxNWNhYzUzMTEyYTVjZTM5YTVkYjc3NWMyMmExMGM3YTZiYTc3MDMwZDlh
11
+ NjYzZDNiNTZhMDFlYTMzNzJmMDVkOTBiYTYxMGIxMDhmM2M1OGE=
12
+ data.tar.gz: !binary |-
13
+ ZTcyYTJkZTM4ZmNiMDcyOWVkNDY3MzQxYjdiNDBkOTQzN2E2OWRmYjQzMmEx
14
+ ODg3OTQ1NDc4ZjBjYmY1YTRmODMwNmQyMjNhYWQ2OTZmMDAxOWVkZTUzMmVj
15
+ YTY3ZTgyYmQ2MDVhMjQzMTA4NTdhNGU1YzZlM2FhMGJmMDQyOWY=
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # ruby-xcdm
2
2
 
3
- This is a tool for generating the same xcdatamodeld files that XCode does when designing a datamodel for Core Data.
4
- It is written in pure ruby, but it will be of particular interest to RubyMotion developers.
3
+ This is a tool for generating the same xcdatamodeld files that XCode does when
4
+ designing a datamodel for Core Data. It is written in pure ruby, but it will
5
+ be of particular interest to RubyMotion developers. It offers the essential
6
+ features that XCode does, plus a text-based workflow (nicer for git, among
7
+ other things) and some niceties, like automatic inverse relationships.
5
8
 
6
9
  ## Installation
7
10
 
@@ -17,7 +20,20 @@ Or install it yourself as:
17
20
 
18
21
  $ gem install ruby-xcdm
19
22
 
20
- ## Usage
23
+ ## Usage (RubyMotion)
24
+
25
+ 1. Make a directory called "schemas" inside your RubyMotion project
26
+ 2. Create one schema version per file within the directory
27
+ 3. To build the schema, run `rake schema:build`
28
+
29
+ If you want to build the schema every time you run the simulator, add this to
30
+ your Rakefile:
31
+
32
+ ```ruby
33
+ task :"build:simulator" => :"schema:build"
34
+ ```
35
+
36
+ ## Usage (Plain Ruby)
21
37
 
22
38
  1. Make a directory to hold your schemas (a.k.a. data model in XCode parlance)
23
39
  2. Create one schema version per file within the directory
@@ -30,6 +46,7 @@ Or install it yourself as:
30
46
 
31
47
  Here's a sample schema file:
32
48
 
49
+ ```ruby
33
50
  schema "0.0.1" do
34
51
 
35
52
  entity "Article" do
@@ -40,7 +57,7 @@ Here's a sample schema file:
40
57
  datetime :publishedAt, default: false
41
58
  string :title, optional: false
42
59
 
43
- has_one :author
60
+ belongs_to :author
44
61
  end
45
62
 
46
63
  entity "Author" do
@@ -50,10 +67,12 @@ Here's a sample schema file:
50
67
  end
51
68
 
52
69
  end
70
+ ```
53
71
 
54
- It's pretty self-explanatory. All the built-in data types are supported, and inverse relationships are
55
- generated automatically. If you need to set some of the more esoteric options on properties or
56
- relationships, you can include the raw parameters, like renamingIdentifier or defaultValueString.
72
+ All the built-in data types are supported, and inverse relationships are
73
+ generated automatically. If you need to set some of the more esoteric options
74
+ on properties or relationships, you can include the raw parameters, like
75
+ renamingIdentifier or defaultValueString.
57
76
 
58
77
  ## Contributing
59
78
 
@@ -24,15 +24,24 @@ module XCDM
24
24
  }
25
25
 
26
26
 
27
- attr_reader :name, :properties, :relationships, :class_name
27
+ attr_reader :name, :properties, :relationships, :class_name, :parent, :abstract
28
28
 
29
29
 
30
30
  def initialize(schema, name, options = {})
31
+ @options = options.dup
31
32
  @schema = schema
32
33
  @name = name
33
- @class_name = options[:class_name] || name
34
+ @class_name = @options.delete(:class_name) || name
34
35
  @properties = []
35
36
  @relationships = []
37
+ @parent = @options.delete(:parent)
38
+ if @parent
39
+ @options['parentEntity'] = parent
40
+ end
41
+ @abstract = @options.delete(:abstract)
42
+ if @abstract
43
+ @options['isAbstract'] = normalize_value(@abstract)
44
+ end
36
45
  end
37
46
 
38
47
  def raw_property(options)
@@ -93,7 +102,7 @@ module XCDM
93
102
  end
94
103
 
95
104
  def belongs_to(name, options = {})
96
- case @schema.xcode_version
105
+ case @schema.xcode_version
97
106
  when /4\..*/
98
107
  options = {maxCount: 1, minCount: 1, plural_inverse: true}.merge(options)
99
108
  else
@@ -103,7 +112,7 @@ module XCDM
103
112
  end
104
113
 
105
114
  def has_one(name, options = {})
106
- case @schema.xcode_version
115
+ case @schema.xcode_version
107
116
  when /4\..*/
108
117
  options = {maxCount: 1, minCount: 1}.merge(options)
109
118
  else
@@ -113,7 +122,7 @@ module XCDM
113
122
  end
114
123
 
115
124
  def has_many(name, options = {})
116
- case @schema.xcode_version
125
+ case @schema.xcode_version
117
126
  when /4\..*/
118
127
  options = {maxCount: -1, minCount: 1}.merge(options)
119
128
  else
@@ -129,7 +138,8 @@ module XCDM
129
138
 
130
139
  def to_xml(builder = nil)
131
140
  builder ||= Builder::XmlMarkup.new(:indent => 2)
132
- builder.entity(name: name, syncable: 'YES', representedClassName: class_name ) do |xml|
141
+ options = { name: name, syncable: 'YES', representedClassName: class_name }.merge(@options)
142
+ builder.entity(options) do |xml|
133
143
  properties.each do |property|
134
144
  xml.attribute(property)
135
145
  end
@@ -68,8 +68,9 @@ module XCDM
68
68
  @schemas = []
69
69
  end
70
70
 
71
- def schema(version, &block)
72
- @found_schema = Schema.new(version, xcode_version).tap { |s| s.instance_eval(&block) }
71
+ def schema(version, options = {}, &block)
72
+ xcv = options[:xcode_version] || xcode_version
73
+ @found_schema = Schema.new(version, xcv).tap { |s| s.instance_eval(&block) }
73
74
  @schemas << @found_schema
74
75
  end
75
76
 
@@ -1,3 +1,3 @@
1
1
  module XCDM
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -7,9 +7,12 @@ require 'rexml/document'
7
7
  module XCDM
8
8
  class EntityTest < Test::Unit::TestCase
9
9
 
10
- def e
10
+ attr_reader :e, :pub
11
+
12
+ def setup
11
13
  s = Schema.new("0.0.1", "4.6")
12
- @e ||= Entity.new(s, "Article")
14
+ @pub ||= Entity.new(s, "Publication", abstract: true)
15
+ @e ||= Entity.new(s, "Article", parent: "Publication")
13
16
  end
14
17
 
15
18
  def test_initialize
@@ -56,6 +59,14 @@ module XCDM
56
59
  assert_equal 'Transformable', Entity.convert_type(:transformable)
57
60
  end
58
61
 
62
+ def test_parent_entity
63
+ assert_equal 'Publication', e.parent
64
+ end
65
+
66
+ def test_abstract_entity
67
+ assert pub.abstract
68
+ end
69
+
59
70
  def test_raw_relationship
60
71
  opts = { name: "author", minCount: "1", maxCount: "1", destinationEntity: "Author", inverseName: "articles", inverseEntity: "Author" }
61
72
  e.raw_relationship(opts)
@@ -99,7 +110,7 @@ module XCDM
99
110
 
100
111
  def test_to_xml
101
112
  expected = REXML::Document.new %{
102
- <entity name="Article" representedClassName="Article" syncable="YES">
113
+ <entity name="Article" representedClassName="Article" parentEntity="Publication" syncable="YES">
103
114
  <attribute name="body" optional="NO" attributeType="String" syncable="YES"/>
104
115
  <attribute name="length" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
105
116
  <attribute name="published" optional="YES" attributeType="Boolean" defaultValueString="NO" syncable="YES"/>
@@ -119,6 +130,12 @@ module XCDM
119
130
 
120
131
  assert_equal expected.to_s.strip, REXML::Document.new(e.to_xml).to_s.strip
121
132
 
133
+ expected = REXML::Document.new %{
134
+ <entity name="Publication" representedClassName="Publication" isAbstract="YES" syncable="YES">
135
+ </entity>
136
+ }
137
+
138
+ assert_equal expected.to_s.strip, REXML::Document.new(pub.to_xml).to_s.strip
122
139
  end
123
140
 
124
141
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-xcdm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ken Miller
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-14 00:00:00.000000000 Z
11
+ date: 2013-12-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: builder
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: activesupport
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: plist
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: bundler
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: turn
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ! '>='
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ! '>='
108
95
  - !ruby/object:Gem::Version
@@ -137,30 +124,30 @@ files:
137
124
  homepage: https://github.com/infinitered/ruby-xcdm
138
125
  licenses:
139
126
  - MIT
127
+ metadata: {}
140
128
  post_install_message:
141
129
  rdoc_options: []
142
130
  require_paths:
143
131
  - lib
144
132
  required_ruby_version: !ruby/object:Gem::Requirement
145
- none: false
146
133
  requirements:
147
134
  - - ! '>='
148
135
  - !ruby/object:Gem::Version
149
136
  version: '0'
150
137
  required_rubygems_version: !ruby/object:Gem::Requirement
151
- none: false
152
138
  requirements:
153
139
  - - ! '>='
154
140
  - !ruby/object:Gem::Version
155
141
  version: '0'
156
142
  requirements: []
157
143
  rubyforge_project:
158
- rubygems_version: 1.8.23
144
+ rubygems_version: 2.1.5
159
145
  signing_key:
160
- specification_version: 3
146
+ specification_version: 4
161
147
  summary: Ruby XCDM
162
148
  test_files:
163
149
  - test/entity_test.rb
164
150
  - test/fixtures/001_baseline.rb
165
151
  - test/fixtures/Article.xcdatamodeld/Article.xcdatamodel/contents
166
152
  - test/schema_test.rb
153
+ has_rdoc: