motion_migrate 0.1.0

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.
Files changed (43) hide show
  1. data/.gitignore +17 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +152 -0
  6. data/Rakefile +3 -0
  7. data/lib/motion_migrate/generate.rb +51 -0
  8. data/lib/motion_migrate/model.rb +10 -0
  9. data/lib/motion_migrate/motion_generate/entity.rb +15 -0
  10. data/lib/motion_migrate/motion_generate/io.rb +79 -0
  11. data/lib/motion_migrate/motion_generate/parser.rb +27 -0
  12. data/lib/motion_migrate/motion_generate/property.rb +171 -0
  13. data/lib/motion_migrate/motion_generate/relationship.rb +153 -0
  14. data/lib/motion_migrate/motion_model/property.rb +14 -0
  15. data/lib/motion_migrate/motion_model/relationship.rb +20 -0
  16. data/lib/motion_migrate.rb +20 -0
  17. data/lib/tasks/migrate.rake +53 -0
  18. data/lib/version.rb +3 -0
  19. data/motion_migrate.gemspec +21 -0
  20. data/spec/property_spec.rb +113 -0
  21. data/spec/relationship_spec.rb +54 -0
  22. data/spec_project/.gitignore +18 -0
  23. data/spec_project/Gemfile +6 -0
  24. data/spec_project/Rakefile +14 -0
  25. data/spec_project/app/app_delegate.rb +7 -0
  26. data/spec_project/app/models/pilot.rb +7 -0
  27. data/spec_project/app/models/plane.rb +11 -0
  28. data/spec_project/db/schema.xcdatamodeld/.xccurrentversion +8 -0
  29. data/spec_project/db/schema.xcdatamodeld/schema.1.xcdatamodel/contents +6 -0
  30. data/spec_project/db/schema.xcdatamodeld/schema.10.xcdatamodel/contents +18 -0
  31. data/spec_project/db/schema.xcdatamodeld/schema.2.xcdatamodel/contents +7 -0
  32. data/spec_project/db/schema.xcdatamodeld/schema.3.xcdatamodel/contents +7 -0
  33. data/spec_project/db/schema.xcdatamodeld/schema.4.xcdatamodel/contents +8 -0
  34. data/spec_project/db/schema.xcdatamodeld/schema.5.xcdatamodel/contents +9 -0
  35. data/spec_project/db/schema.xcdatamodeld/schema.6.xcdatamodel/contents +13 -0
  36. data/spec_project/db/schema.xcdatamodeld/schema.7.xcdatamodel/contents +14 -0
  37. data/spec_project/db/schema.xcdatamodeld/schema.8.xcdatamodel/contents +16 -0
  38. data/spec_project/db/schema.xcdatamodeld/schema.9.xcdatamodel/contents +16 -0
  39. data/spec_project/spec/helper.rb +8 -0
  40. data/spec_project/spec/property_spec.rb +57 -0
  41. data/spec_project/spec/relationship_spec.rb +105 -0
  42. data/spec_project/vendor/Podfile.lock +11 -0
  43. metadata +113 -0
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1811" systemVersion="11D50" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
3
+ <entity name="Plane" representedClassName="Plane" syncable="YES">
4
+ <attribute name="name" attributeType="String" optional="YES" syncable="YES"/>
5
+ <attribute name="multi_engine" attributeType="Boolean" optional="YES" syncable="YES" defaultValueString="NO"/>
6
+ <attribute name="first_flight_at" attributeType="Date" optional="YES" syncable="YES"/>
7
+ <attribute name="flight_info" attributeType="Binary" optional="YES" syncable="YES"/>
8
+ <relationship name="pilot" optional="YES" deletionRule="No Action" syncable="YES" minCount="1" maxCount="1" inverseEntity="Pilot" destinationEntity="Pilot" inverseName="plane" toMany="NO"/>
9
+ <relationship name="owner" optional="YES" deletionRule="No Action" syncable="YES" minCount="1" maxCount="1" inverseEntity="Pilot" destinationEntity="Pilot" inverseName="owned_planes" toMany="NO"/>
10
+ </entity>
11
+ <entity name="Pilot" representedClassName="Pilot" syncable="YES">
12
+ <attribute name="name" attributeType="String" optional="YES" syncable="YES"/>
13
+ <relationship name="plane" optional="YES" deletionRule="No Action" syncable="YES" minCount="1" maxCount="1" inverseEntity="Plane" destinationEntity="Plane" inverseName="pilot" toMany="NO"/>
14
+ <relationship name="owned_planes" optional="YES" deletionRule="No Action" syncable="YES" minCount="1" maxCount="1" inverseEntity="Plane" destinationEntity="Plane" inverseName="owner" toMany="NO"/>
15
+ </entity>
16
+ </model>
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1811" systemVersion="11D50" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
3
+ <entity name="Pilot" representedClassName="Pilot" syncable="YES">
4
+ <attribute name="name" attributeType="String" optional="YES" syncable="YES"/>
5
+ <relationship name="plane" optional="YES" deletionRule="No Action" syncable="YES" minCount="1" maxCount="1" inverseEntity="Plane" destinationEntity="Plane" inverseName="pilot" toMany="NO"/>
6
+ <relationship name="owned_planes" optional="YES" deletionRule="No Action" syncable="YES" inverseEntity="Plane" destinationEntity="Plane" inverseName="owner" toMany="YES"/>
7
+ </entity>
8
+ <entity name="Plane" representedClassName="Plane" syncable="YES">
9
+ <attribute name="name" attributeType="String" optional="YES" syncable="YES"/>
10
+ <attribute name="multi_engine" attributeType="Boolean" optional="YES" syncable="YES" defaultValueString="NO"/>
11
+ <attribute name="first_flight_at" attributeType="Date" optional="YES" syncable="YES"/>
12
+ <attribute name="flight_info" attributeType="Binary" optional="YES" syncable="YES"/>
13
+ <relationship name="pilot" optional="YES" deletionRule="No Action" syncable="YES" minCount="1" maxCount="1" inverseEntity="Pilot" destinationEntity="Pilot" inverseName="plane" toMany="NO"/>
14
+ <relationship name="owner" optional="YES" deletionRule="No Action" syncable="YES" minCount="1" maxCount="1" inverseEntity="Pilot" destinationEntity="Pilot" inverseName="owned_planes" toMany="NO"/>
15
+ </entity>
16
+ </model>
@@ -0,0 +1,8 @@
1
+ def reset
2
+ Plane.MR_truncateAll
3
+ Pilot.MR_truncateAll
4
+ end
5
+
6
+ def save
7
+ NSManagedObjectContext.contextForCurrentThread.MR_saveToPersistentStoreAndWait
8
+ end
@@ -0,0 +1,57 @@
1
+ describe "properties in a model" do
2
+ it "should set the property name on the model" do
3
+ reset
4
+
5
+ new_plane = Plane.MR_createEntity
6
+ new_plane.name.should == nil
7
+ new_plane.name = "Airbus 380"
8
+ new_plane.name.should == "Airbus 380"
9
+ save
10
+
11
+ fetched_plane = Plane.MR_findFirst
12
+ fetched_plane.name.should == "Airbus 380"
13
+ end
14
+
15
+ it "should set the boolean property on the model" do
16
+ reset
17
+
18
+ new_plane = Plane.MR_createEntity
19
+ new_plane.multi_engine.boolValue.should == false
20
+ new_plane.multi_engine = true
21
+ new_plane.multi_engine.class.should == Fixnum
22
+ save
23
+
24
+ fetched_plane = Plane.MR_findFirst
25
+ fetched_plane.multi_engine.boolValue.should == true
26
+ end
27
+
28
+ it "should set the date property on the model" do
29
+ reset
30
+
31
+ new_plane = Plane.MR_createEntity
32
+ new_plane.first_flight_at.should == nil
33
+ date = NSDate.date
34
+ new_plane.first_flight_at = date
35
+ new_plane.first_flight_at.should == date
36
+ new_plane.first_flight_at.class.should == Time
37
+ save
38
+
39
+ fetched_plane = Plane.MR_findFirst
40
+ fetched_plane.first_flight_at.should == date
41
+ end
42
+
43
+ it "should set the data property on the model" do
44
+ reset
45
+
46
+ new_plane = Plane.MR_createEntity
47
+ new_plane.flight_info.should == nil
48
+ flight_info = NSKeyedArchiver.archivedDataWithRootObject({ crew: ["First officer", "Last officer"] })
49
+ new_plane.flight_info = flight_info
50
+ new_plane.flight_info.should == flight_info
51
+ new_plane.flight_info.class.should == NSConcreteMutableData
52
+ save
53
+
54
+ fetched_plane = Plane.MR_findFirst
55
+ fetched_plane.flight_info.should == flight_info
56
+ end
57
+ end
@@ -0,0 +1,105 @@
1
+ describe "relationship in a model" do
2
+ it "should set the belongs to property both ways on the models" do
3
+ reset
4
+
5
+ new_plane = Plane.MR_createEntity
6
+ new_plane.pilot.class.should == NilClass
7
+ new_plane.name = "X1"
8
+ new_pilot = Pilot.MR_createEntity
9
+ new_pilot.name = "Chuck Yeager"
10
+ new_pilot.plane.class.should == NilClass
11
+ new_plane.pilot = new_pilot
12
+ new_plane.pilot.name.should == new_pilot.name
13
+ new_pilot.plane.name.should == new_plane.name
14
+ save
15
+
16
+ fetched_plane = Plane.MR_findFirst
17
+ fetched_pilot = Pilot.MR_findFirst
18
+ fetched_plane.pilot.name.should == "Chuck Yeager"
19
+ fetched_pilot.plane.name.should == "X1"
20
+ fetched_pilot.plane = nil
21
+ save
22
+
23
+ fetched_plane = Plane.MR_findFirst
24
+ fetched_pilot = Pilot.MR_findFirst
25
+ fetched_plane.pilot.class.should == NilClass
26
+ fetched_pilot.plane.class.should == NilClass
27
+ end
28
+
29
+ it "should set the belongs to and has many relation on the models" do
30
+ reset
31
+
32
+ new_plane = Plane.MR_createEntity
33
+ new_plane.owner.class.should == NilClass
34
+ new_plane.name = "X1"
35
+ new_other_plane = Plane.MR_createEntity
36
+ new_other_plane.name = "P-51 Mustang"
37
+ new_pilot = Pilot.MR_createEntity
38
+ new_pilot.name = "Chuck Yeager"
39
+ new_pilot.owned_planes.count.should == 0
40
+ # Test relation belongs to property
41
+ new_plane.owner = new_pilot
42
+ new_plane.owner.name.should == new_pilot.name
43
+ new_pilot.primitiveOwned_planes.count.should == 1
44
+ new_pilot.owned_planes.allObjects.first.name.should == "X1"
45
+ # Test relation has many addObject setter
46
+ new_pilot.addOwned_planesObject(new_other_plane)
47
+ new_pilot.owned_planes.allObjects.count.should == 2
48
+ save
49
+
50
+ fetched_plane = Plane.MR_findFirst
51
+ fetched_pilot = Pilot.MR_findFirst
52
+ fetched_plane.owner.name.should == "Chuck Yeager"
53
+ fetched_pilot.owned_planes.allObjects.count.should == 2
54
+ fetched_pilot.owned_planes.allObjects.sort_by(&:name).each do |p|
55
+ p.name.class.should == String
56
+ end
57
+ fetched_pilot.removeOwned_planesObject(fetched_plane)
58
+ fetched_pilot.owned_planes.allObjects.count.should == 1
59
+ save
60
+
61
+ fetched_pilot = Pilot.MR_findFirst
62
+ fetched_pilot.owned_planes.allObjects.count.should == 1
63
+ fetched_plane = Plane.MR_findFirst
64
+ fetched_plane.owner.should == nil
65
+
66
+ new_plane = Plane.MR_createEntity
67
+ new_plane.name = "ASW-27"
68
+ new_other_plane = Plane.MR_createEntity
69
+ new_other_plane.name = "Diana 2"
70
+ new_pilot = Pilot.MR_createEntity
71
+ new_pilot.name = "Sébastien Kawa"
72
+ new_pilot.owned_planes = NSSet.setWithArray([new_plane, new_other_plane])
73
+ new_pilot.owned_planes.count.should == 2
74
+ new_plane.owner.name.should == "Sébastien Kawa"
75
+ save
76
+ end
77
+
78
+ it "should set the has many relation both ways on the models" do
79
+ reset
80
+
81
+ new_plane = Plane.MR_createEntity
82
+ new_plane.owner.class.should == NilClass
83
+ new_plane.name = "X1"
84
+ new_other_plane = Plane.MR_createEntity
85
+ new_other_plane.name = "P-51 Mustang"
86
+ new_plane.flown_by_pilots.count.should == 0
87
+
88
+ new_pilot = Pilot.MR_createEntity
89
+ new_pilot.name = "Chuck Yeager"
90
+ new_other_pilot = Pilot.MR_createEntity
91
+ new_other_pilot.name = "Sébastien Kawa"
92
+ new_pilot.flown_planes.count.should == 0
93
+
94
+ new_pilot.addFlown_planesObject(new_plane)
95
+ new_pilot.addFlown_planesObject(new_other_plane)
96
+
97
+ new_pilot.flown_planes.allObjects.count.should == 2
98
+ new_plane.flown_by_pilots.allObjects.count.should == 1
99
+ new_other_plane.flown_by_pilots.allObjects.count.should == 1
100
+ new_other_pilot.addFlown_planesObject(new_plane)
101
+ new_other_pilot.flown_planes.count.should == 1
102
+ new_plane.flown_by_pilots.allObjects.count.should == 2
103
+ save
104
+ end
105
+ end
@@ -0,0 +1,11 @@
1
+
2
+ PODS:
3
+ - MagicalRecord (2.1)
4
+
5
+ DEPENDENCIES:
6
+ - MagicalRecord (= 2.1)
7
+
8
+ SPEC CHECKSUMS:
9
+ MagicalRecord: aedbebe987d02d1215718a904c93d7965e48e398
10
+
11
+ COCOAPODS: 0.16.2
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion_migrate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jelle Vandebeeck
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70215316589340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70215316589340
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ requirement: &70215316588460 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70215316588460
36
+ description: Generate the Core Data model from your RubyMotion code.
37
+ email:
38
+ - jelle@fousa.be
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - .rvmrc
45
+ - Gemfile
46
+ - LICENSE.txt
47
+ - README.md
48
+ - Rakefile
49
+ - lib/motion_migrate.rb
50
+ - lib/motion_migrate/generate.rb
51
+ - lib/motion_migrate/model.rb
52
+ - lib/motion_migrate/motion_generate/entity.rb
53
+ - lib/motion_migrate/motion_generate/io.rb
54
+ - lib/motion_migrate/motion_generate/parser.rb
55
+ - lib/motion_migrate/motion_generate/property.rb
56
+ - lib/motion_migrate/motion_generate/relationship.rb
57
+ - lib/motion_migrate/motion_model/property.rb
58
+ - lib/motion_migrate/motion_model/relationship.rb
59
+ - lib/tasks/migrate.rake
60
+ - lib/version.rb
61
+ - motion_migrate.gemspec
62
+ - spec/property_spec.rb
63
+ - spec/relationship_spec.rb
64
+ - spec_project/.gitignore
65
+ - spec_project/Gemfile
66
+ - spec_project/Rakefile
67
+ - spec_project/app/app_delegate.rb
68
+ - spec_project/app/models/pilot.rb
69
+ - spec_project/app/models/plane.rb
70
+ - spec_project/db/schema.xcdatamodeld/.xccurrentversion
71
+ - spec_project/db/schema.xcdatamodeld/schema.1.xcdatamodel/contents
72
+ - spec_project/db/schema.xcdatamodeld/schema.10.xcdatamodel/contents
73
+ - spec_project/db/schema.xcdatamodeld/schema.2.xcdatamodel/contents
74
+ - spec_project/db/schema.xcdatamodeld/schema.3.xcdatamodel/contents
75
+ - spec_project/db/schema.xcdatamodeld/schema.4.xcdatamodel/contents
76
+ - spec_project/db/schema.xcdatamodeld/schema.5.xcdatamodel/contents
77
+ - spec_project/db/schema.xcdatamodeld/schema.6.xcdatamodel/contents
78
+ - spec_project/db/schema.xcdatamodeld/schema.7.xcdatamodel/contents
79
+ - spec_project/db/schema.xcdatamodeld/schema.8.xcdatamodel/contents
80
+ - spec_project/db/schema.xcdatamodeld/schema.9.xcdatamodel/contents
81
+ - spec_project/spec/helper.rb
82
+ - spec_project/spec/property_spec.rb
83
+ - spec_project/spec/relationship_spec.rb
84
+ - spec_project/vendor/Podfile.lock
85
+ homepage: http://fousa.github.com/motion_migrate/
86
+ licenses: []
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.15
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Generate the Core Data model from your RubyMotion code. Never open XCode
109
+ again!
110
+ test_files:
111
+ - spec/property_spec.rb
112
+ - spec/relationship_spec.rb
113
+ has_rdoc: