moblues 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -5
  3. data/lib/moblues/cli.rb +3 -4
  4. data/lib/moblues/generator/base/model.rb +24 -0
  5. data/lib/moblues/generator/base/type.rb +63 -0
  6. data/lib/moblues/generator/objc/base.rb +67 -0
  7. data/lib/moblues/generator/objc/human.rb +27 -0
  8. data/lib/moblues/generator/{human_header.h.erb → objc/human_header.h.erb} +0 -0
  9. data/lib/moblues/generator/{human_implementation.m.erb → objc/human_implementation.m.erb} +0 -0
  10. data/lib/moblues/generator/objc/machine.rb +31 -0
  11. data/lib/moblues/generator/{machine_header.h.erb → objc/machine_header.h.erb} +2 -2
  12. data/lib/moblues/generator/{machine_implementation.m.erb → objc/machine_implementation.m.erb} +0 -0
  13. data/lib/moblues/generator/objc/type.rb +24 -0
  14. data/lib/moblues/generator/swift/base.rb +39 -0
  15. data/lib/moblues/generator/swift/human.rb +18 -0
  16. data/lib/moblues/generator/swift/human.swift.erb +4 -0
  17. data/lib/moblues/generator/swift/machine.rb +18 -0
  18. data/lib/moblues/generator/swift/machine.swift.erb +12 -0
  19. data/lib/moblues/generator.rb +9 -4
  20. data/lib/moblues/reader/type.rb +3 -37
  21. data/lib/moblues/version.rb +1 -1
  22. data/lib/moblues.rb +20 -4
  23. data/spec/features/moblues_spec.rb +35 -16
  24. data/spec/lib/moblues/cli_spec.rb +12 -2
  25. data/spec/lib/moblues/generator/base/model_spec.rb +27 -0
  26. data/spec/lib/moblues/generator/base/type_spec.rb +46 -0
  27. data/spec/lib/moblues/generator/objc/human_spec.rb +54 -0
  28. data/spec/lib/moblues/generator/{machine_spec.rb → objc/machine_spec.rb} +9 -8
  29. data/spec/lib/moblues/generator/objc/type_spec.rb +23 -0
  30. data/spec/lib/moblues/generator/swift/human_spec.rb +34 -0
  31. data/spec/lib/moblues/generator/swift/machine_spec.rb +57 -0
  32. data/spec/lib/moblues/reader/type_spec.rb +3 -54
  33. data/spec/moblues_spec.rb +46 -12
  34. data/spec/resources/expected/{Author.h → objc/Author.h} +0 -0
  35. data/spec/resources/expected/{Author.m → objc/Author.m} +0 -0
  36. data/spec/resources/expected/{_Author.h → objc/_Author.h} +0 -0
  37. data/spec/resources/expected/{_Author.m → objc/_Author.m} +0 -0
  38. data/spec/resources/expected/{_Book.h → objc/_Book.h} +0 -0
  39. data/spec/resources/expected/{_Book.m → objc/_Book.m} +0 -0
  40. data/spec/resources/expected/{_Person.h → objc/_Person.h} +0 -0
  41. data/spec/resources/expected/{_Person.m → objc/_Person.m} +0 -0
  42. data/spec/resources/expected/{_Team.h → objc/_Team.h} +0 -0
  43. data/spec/resources/expected/{_Team.m → objc/_Team.m} +0 -0
  44. data/spec/resources/expected/{human → objc/human}/Playable.h +0 -0
  45. data/spec/resources/expected/{human → objc/human}/Playable.m +0 -0
  46. data/spec/resources/expected/{human → objc/human}/Playlist.h +0 -0
  47. data/spec/resources/expected/{human → objc/human}/Playlist.m +0 -0
  48. data/spec/resources/expected/{human → objc/human}/Track.h +0 -0
  49. data/spec/resources/expected/{human → objc/human}/Track.m +0 -0
  50. data/spec/resources/expected/{human → objc/human}/User.h +0 -0
  51. data/spec/resources/expected/{human → objc/human}/User.m +0 -0
  52. data/spec/resources/expected/{machine → objc/machine}/_Playable.h +0 -0
  53. data/spec/resources/expected/{machine → objc/machine}/_Playable.m +0 -0
  54. data/spec/resources/expected/{machine → objc/machine}/_Playlist.h +0 -0
  55. data/spec/resources/expected/{machine → objc/machine}/_Playlist.m +0 -0
  56. data/spec/resources/expected/{machine → objc/machine}/_Track.h +0 -0
  57. data/spec/resources/expected/{machine → objc/machine}/_Track.m +0 -0
  58. data/spec/resources/expected/{machine → objc/machine}/_User.h +0 -0
  59. data/spec/resources/expected/{machine → objc/machine}/_User.m +0 -0
  60. data/spec/resources/expected/swift/Author.swift +4 -0
  61. data/spec/resources/expected/swift/_Author.swift +11 -0
  62. data/spec/resources/expected/swift/_Book.swift +8 -0
  63. data/spec/resources/expected/swift/human/Playable.swift +4 -0
  64. data/spec/resources/expected/swift/human/Playlist.swift +5 -0
  65. data/spec/resources/expected/swift/human/Track.swift +4 -0
  66. data/spec/resources/expected/swift/human/User.swift +4 -0
  67. data/spec/resources/expected/swift/machine/_Playable.swift +8 -0
  68. data/spec/resources/expected/swift/machine/_Playlist.swift +8 -0
  69. data/spec/resources/expected/swift/machine/_Track.swift +9 -0
  70. data/spec/resources/expected/swift/machine/_User.swift +10 -0
  71. data/spec/resources/factories/data_model/attribute_factory.rb +28 -0
  72. data/spec/resources/factories/data_model/relationship_factory.rb +15 -0
  73. data/spec/resources/fixtures.rb +10 -10
  74. data/spec/resources/tmp/{human → objc/human}/Playlist.h +0 -0
  75. data/spec/resources/tmp/{human → objc/human}/Playlist.m +0 -0
  76. data/spec/resources/tmp/swift/.gitkeep +0 -0
  77. data/spec/resources/tmp/swift/human/Playlist.swift +5 -0
  78. metadata +113 -76
  79. data/lib/moblues/generator/base.rb +0 -65
  80. data/lib/moblues/generator/human.rb +0 -25
  81. data/lib/moblues/generator/machine.rb +0 -36
  82. data/lib/moblues/generator/model.rb +0 -23
  83. data/spec/lib/moblues/generator/human_spec.rb +0 -74
  84. data/spec/lib/moblues/generator/model_spec.rb +0 -27
  85. data/spec/resources/tmp/_Team.h +0 -18
  86. data/spec/resources/tmp/_Team.m +0 -5
@@ -5,29 +5,29 @@ module Fixtures
5
5
  'spec/resources/Model.xcdatamodeld'
6
6
  end
7
7
 
8
- def expected_dir
9
- 'spec/resources/expected'
8
+ def expected_dir(language)
9
+ "spec/resources/expected/#{language}"
10
10
  end
11
11
 
12
- def generated_dir
13
- 'spec/resources/tmp'
12
+ def generated_dir(language)
13
+ "spec/resources/tmp/#{language}"
14
14
  end
15
15
 
16
- def generated_file_content(name)
17
- read_file(generated_dir, name)
16
+ def generated_file_content(name, language)
17
+ read_file(generated_dir(language), name)
18
18
  end
19
19
 
20
- def expected_content(name)
21
- read_file(expected_dir, name)
20
+ def expected_content(name, language)
21
+ read_file(expected_dir(language), name)
22
22
  end
23
23
 
24
24
  def read_file(directory, file)
25
25
  File.read(File.join(directory, file))
26
26
  end
27
27
 
28
- def delete_tmp_files(files)
28
+ def delete_tmp_files(files, language)
29
29
  files.each { |file|
30
- path = File.join(generated_dir, file)
30
+ path = File.join(generated_dir(language), file)
31
31
  File.delete(path) if File.exists?(path)
32
32
  }
33
33
  end
File without changes
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ import Foundation
2
+
3
+ class Playlist: _Playlist {
4
+ /* some modifications that should not be erased */
5
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moblues
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Garrigues
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-05 00:00:00.000000000 Z
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -135,14 +135,21 @@ files:
135
135
  - lib/moblues/data_model/entity.rb
136
136
  - lib/moblues/data_model/relationship.rb
137
137
  - lib/moblues/generator.rb
138
- - lib/moblues/generator/base.rb
139
- - lib/moblues/generator/human.rb
140
- - lib/moblues/generator/human_header.h.erb
141
- - lib/moblues/generator/human_implementation.m.erb
142
- - lib/moblues/generator/machine.rb
143
- - lib/moblues/generator/machine_header.h.erb
144
- - lib/moblues/generator/machine_implementation.m.erb
145
- - lib/moblues/generator/model.rb
138
+ - lib/moblues/generator/base/model.rb
139
+ - lib/moblues/generator/base/type.rb
140
+ - lib/moblues/generator/objc/base.rb
141
+ - lib/moblues/generator/objc/human.rb
142
+ - lib/moblues/generator/objc/human_header.h.erb
143
+ - lib/moblues/generator/objc/human_implementation.m.erb
144
+ - lib/moblues/generator/objc/machine.rb
145
+ - lib/moblues/generator/objc/machine_header.h.erb
146
+ - lib/moblues/generator/objc/machine_implementation.m.erb
147
+ - lib/moblues/generator/objc/type.rb
148
+ - lib/moblues/generator/swift/base.rb
149
+ - lib/moblues/generator/swift/human.rb
150
+ - lib/moblues/generator/swift/human.swift.erb
151
+ - lib/moblues/generator/swift/machine.rb
152
+ - lib/moblues/generator/swift/machine.swift.erb
146
153
  - lib/moblues/reader.rb
147
154
  - lib/moblues/reader/attribute.rb
148
155
  - lib/moblues/reader/entity.rb
@@ -157,9 +164,13 @@ files:
157
164
  - spec/lib/moblues/data_model/attribute_spec.rb
158
165
  - spec/lib/moblues/data_model/entity_spec.rb
159
166
  - spec/lib/moblues/data_model/relationship_spec.rb
160
- - spec/lib/moblues/generator/human_spec.rb
161
- - spec/lib/moblues/generator/machine_spec.rb
162
- - spec/lib/moblues/generator/model_spec.rb
167
+ - spec/lib/moblues/generator/base/model_spec.rb
168
+ - spec/lib/moblues/generator/base/type_spec.rb
169
+ - spec/lib/moblues/generator/objc/human_spec.rb
170
+ - spec/lib/moblues/generator/objc/machine_spec.rb
171
+ - spec/lib/moblues/generator/objc/type_spec.rb
172
+ - spec/lib/moblues/generator/swift/human_spec.rb
173
+ - spec/lib/moblues/generator/swift/machine_spec.rb
163
174
  - spec/lib/moblues/reader/attribute_spec.rb
164
175
  - spec/lib/moblues/reader/entity_spec.rb
165
176
  - spec/lib/moblues/reader/model_spec.rb
@@ -170,41 +181,52 @@ files:
170
181
  - spec/resources/Model.xcdatamodeld/.xccurrentversion
171
182
  - spec/resources/Model.xcdatamodeld/Model 2.xcdatamodel/contents
172
183
  - spec/resources/Model.xcdatamodeld/Model.xcdatamodel/contents
173
- - spec/resources/expected/Author.h
174
- - spec/resources/expected/Author.m
175
- - spec/resources/expected/_Author.h
176
- - spec/resources/expected/_Author.m
177
- - spec/resources/expected/_Book.h
178
- - spec/resources/expected/_Book.m
179
- - spec/resources/expected/_Person.h
180
- - spec/resources/expected/_Person.m
181
- - spec/resources/expected/_Team.h
182
- - spec/resources/expected/_Team.m
183
- - spec/resources/expected/human/Playable.h
184
- - spec/resources/expected/human/Playable.m
185
- - spec/resources/expected/human/Playlist.h
186
- - spec/resources/expected/human/Playlist.m
187
- - spec/resources/expected/human/Track.h
188
- - spec/resources/expected/human/Track.m
189
- - spec/resources/expected/human/User.h
190
- - spec/resources/expected/human/User.m
191
- - spec/resources/expected/machine/_Playable.h
192
- - spec/resources/expected/machine/_Playable.m
193
- - spec/resources/expected/machine/_Playlist.h
194
- - spec/resources/expected/machine/_Playlist.m
195
- - spec/resources/expected/machine/_Track.h
196
- - spec/resources/expected/machine/_Track.m
197
- - spec/resources/expected/machine/_User.h
198
- - spec/resources/expected/machine/_User.m
184
+ - spec/resources/expected/objc/Author.h
185
+ - spec/resources/expected/objc/Author.m
186
+ - spec/resources/expected/objc/_Author.h
187
+ - spec/resources/expected/objc/_Author.m
188
+ - spec/resources/expected/objc/_Book.h
189
+ - spec/resources/expected/objc/_Book.m
190
+ - spec/resources/expected/objc/_Person.h
191
+ - spec/resources/expected/objc/_Person.m
192
+ - spec/resources/expected/objc/_Team.h
193
+ - spec/resources/expected/objc/_Team.m
194
+ - spec/resources/expected/objc/human/Playable.h
195
+ - spec/resources/expected/objc/human/Playable.m
196
+ - spec/resources/expected/objc/human/Playlist.h
197
+ - spec/resources/expected/objc/human/Playlist.m
198
+ - spec/resources/expected/objc/human/Track.h
199
+ - spec/resources/expected/objc/human/Track.m
200
+ - spec/resources/expected/objc/human/User.h
201
+ - spec/resources/expected/objc/human/User.m
202
+ - spec/resources/expected/objc/machine/_Playable.h
203
+ - spec/resources/expected/objc/machine/_Playable.m
204
+ - spec/resources/expected/objc/machine/_Playlist.h
205
+ - spec/resources/expected/objc/machine/_Playlist.m
206
+ - spec/resources/expected/objc/machine/_Track.h
207
+ - spec/resources/expected/objc/machine/_Track.m
208
+ - spec/resources/expected/objc/machine/_User.h
209
+ - spec/resources/expected/objc/machine/_User.m
210
+ - spec/resources/expected/swift/Author.swift
211
+ - spec/resources/expected/swift/_Author.swift
212
+ - spec/resources/expected/swift/_Book.swift
213
+ - spec/resources/expected/swift/human/Playable.swift
214
+ - spec/resources/expected/swift/human/Playlist.swift
215
+ - spec/resources/expected/swift/human/Track.swift
216
+ - spec/resources/expected/swift/human/User.swift
217
+ - spec/resources/expected/swift/machine/_Playable.swift
218
+ - spec/resources/expected/swift/machine/_Playlist.swift
219
+ - spec/resources/expected/swift/machine/_Track.swift
220
+ - spec/resources/expected/swift/machine/_User.swift
199
221
  - spec/resources/factories/data_model/attribute_factory.rb
200
222
  - spec/resources/factories/data_model/entity_factory.rb
201
223
  - spec/resources/factories/data_model/relationship_factory.rb
202
224
  - spec/resources/fixtures.rb
203
225
  - spec/resources/tmp/.gitkeep
204
- - spec/resources/tmp/_Team.h
205
- - spec/resources/tmp/_Team.m
206
- - spec/resources/tmp/human/Playlist.h
207
- - spec/resources/tmp/human/Playlist.m
226
+ - spec/resources/tmp/objc/human/Playlist.h
227
+ - spec/resources/tmp/objc/human/Playlist.m
228
+ - spec/resources/tmp/swift/.gitkeep
229
+ - spec/resources/tmp/swift/human/Playlist.swift
208
230
  - spec/spec_helper.rb
209
231
  homepage: http://garriguv.io
210
232
  licenses:
@@ -236,9 +258,13 @@ test_files:
236
258
  - spec/lib/moblues/data_model/attribute_spec.rb
237
259
  - spec/lib/moblues/data_model/entity_spec.rb
238
260
  - spec/lib/moblues/data_model/relationship_spec.rb
239
- - spec/lib/moblues/generator/human_spec.rb
240
- - spec/lib/moblues/generator/machine_spec.rb
241
- - spec/lib/moblues/generator/model_spec.rb
261
+ - spec/lib/moblues/generator/base/model_spec.rb
262
+ - spec/lib/moblues/generator/base/type_spec.rb
263
+ - spec/lib/moblues/generator/objc/human_spec.rb
264
+ - spec/lib/moblues/generator/objc/machine_spec.rb
265
+ - spec/lib/moblues/generator/objc/type_spec.rb
266
+ - spec/lib/moblues/generator/swift/human_spec.rb
267
+ - spec/lib/moblues/generator/swift/machine_spec.rb
242
268
  - spec/lib/moblues/reader/attribute_spec.rb
243
269
  - spec/lib/moblues/reader/entity_spec.rb
244
270
  - spec/lib/moblues/reader/model_spec.rb
@@ -249,39 +275,50 @@ test_files:
249
275
  - spec/resources/Model.xcdatamodeld/.xccurrentversion
250
276
  - spec/resources/Model.xcdatamodeld/Model 2.xcdatamodel/contents
251
277
  - spec/resources/Model.xcdatamodeld/Model.xcdatamodel/contents
252
- - spec/resources/expected/Author.h
253
- - spec/resources/expected/Author.m
254
- - spec/resources/expected/_Author.h
255
- - spec/resources/expected/_Author.m
256
- - spec/resources/expected/_Book.h
257
- - spec/resources/expected/_Book.m
258
- - spec/resources/expected/_Person.h
259
- - spec/resources/expected/_Person.m
260
- - spec/resources/expected/_Team.h
261
- - spec/resources/expected/_Team.m
262
- - spec/resources/expected/human/Playable.h
263
- - spec/resources/expected/human/Playable.m
264
- - spec/resources/expected/human/Playlist.h
265
- - spec/resources/expected/human/Playlist.m
266
- - spec/resources/expected/human/Track.h
267
- - spec/resources/expected/human/Track.m
268
- - spec/resources/expected/human/User.h
269
- - spec/resources/expected/human/User.m
270
- - spec/resources/expected/machine/_Playable.h
271
- - spec/resources/expected/machine/_Playable.m
272
- - spec/resources/expected/machine/_Playlist.h
273
- - spec/resources/expected/machine/_Playlist.m
274
- - spec/resources/expected/machine/_Track.h
275
- - spec/resources/expected/machine/_Track.m
276
- - spec/resources/expected/machine/_User.h
277
- - spec/resources/expected/machine/_User.m
278
+ - spec/resources/expected/objc/Author.h
279
+ - spec/resources/expected/objc/Author.m
280
+ - spec/resources/expected/objc/_Author.h
281
+ - spec/resources/expected/objc/_Author.m
282
+ - spec/resources/expected/objc/_Book.h
283
+ - spec/resources/expected/objc/_Book.m
284
+ - spec/resources/expected/objc/_Person.h
285
+ - spec/resources/expected/objc/_Person.m
286
+ - spec/resources/expected/objc/_Team.h
287
+ - spec/resources/expected/objc/_Team.m
288
+ - spec/resources/expected/objc/human/Playable.h
289
+ - spec/resources/expected/objc/human/Playable.m
290
+ - spec/resources/expected/objc/human/Playlist.h
291
+ - spec/resources/expected/objc/human/Playlist.m
292
+ - spec/resources/expected/objc/human/Track.h
293
+ - spec/resources/expected/objc/human/Track.m
294
+ - spec/resources/expected/objc/human/User.h
295
+ - spec/resources/expected/objc/human/User.m
296
+ - spec/resources/expected/objc/machine/_Playable.h
297
+ - spec/resources/expected/objc/machine/_Playable.m
298
+ - spec/resources/expected/objc/machine/_Playlist.h
299
+ - spec/resources/expected/objc/machine/_Playlist.m
300
+ - spec/resources/expected/objc/machine/_Track.h
301
+ - spec/resources/expected/objc/machine/_Track.m
302
+ - spec/resources/expected/objc/machine/_User.h
303
+ - spec/resources/expected/objc/machine/_User.m
304
+ - spec/resources/expected/swift/Author.swift
305
+ - spec/resources/expected/swift/_Author.swift
306
+ - spec/resources/expected/swift/_Book.swift
307
+ - spec/resources/expected/swift/human/Playable.swift
308
+ - spec/resources/expected/swift/human/Playlist.swift
309
+ - spec/resources/expected/swift/human/Track.swift
310
+ - spec/resources/expected/swift/human/User.swift
311
+ - spec/resources/expected/swift/machine/_Playable.swift
312
+ - spec/resources/expected/swift/machine/_Playlist.swift
313
+ - spec/resources/expected/swift/machine/_Track.swift
314
+ - spec/resources/expected/swift/machine/_User.swift
278
315
  - spec/resources/factories/data_model/attribute_factory.rb
279
316
  - spec/resources/factories/data_model/entity_factory.rb
280
317
  - spec/resources/factories/data_model/relationship_factory.rb
281
318
  - spec/resources/fixtures.rb
282
319
  - spec/resources/tmp/.gitkeep
283
- - spec/resources/tmp/_Team.h
284
- - spec/resources/tmp/_Team.m
285
- - spec/resources/tmp/human/Playlist.h
286
- - spec/resources/tmp/human/Playlist.m
320
+ - spec/resources/tmp/objc/human/Playlist.h
321
+ - spec/resources/tmp/objc/human/Playlist.m
322
+ - spec/resources/tmp/swift/.gitkeep
323
+ - spec/resources/tmp/swift/human/Playlist.swift
287
324
  - spec/spec_helper.rb
@@ -1,65 +0,0 @@
1
- require 'erb'
2
- require 'moblues/reader/type'
3
-
4
- module Moblues
5
- module Generator
6
- class Base
7
- def initialize(params)
8
- @output_dir = params.fetch(:output_dir)
9
- end
10
-
11
- protected
12
- attr_reader :output_dir
13
-
14
- def write_header(entity)
15
- write_file(header_file(entity), header(entity))
16
- end
17
-
18
- def write_implementation(entity)
19
- write_file(implementation_file(entity), implementation(entity))
20
- end
21
-
22
- def write_file(file, text)
23
- File.open(file, 'w+') do |f|
24
- f.write(text)
25
- end
26
- end
27
-
28
- def header_file(entity)
29
- File.join(output_dir, format_name(entity, 'h'))
30
- end
31
-
32
- def implementation_file(entity)
33
- File.join(output_dir, format_name(entity, 'm'))
34
- end
35
-
36
- def format_name(entity, extension)
37
- raise NotImplemented
38
- end
39
-
40
- def header(entity)
41
- render(header_template, entity)
42
- end
43
-
44
- def implementation(entity)
45
- render(implementation_template, entity)
46
- end
47
-
48
- def render(template, entity)
49
- ERB.new(template, 0, '-').result(entity.send(:binding))
50
- end
51
-
52
- def header_template
53
- raise NotImplemented
54
- end
55
-
56
- def implementation_template
57
- raise NotImplemented
58
- end
59
-
60
- def file_template(name)
61
- File.read(File.expand_path("../#{name}.erb", __FILE__))
62
- end
63
- end
64
- end
65
- end
@@ -1,25 +0,0 @@
1
- require 'moblues/generator/base'
2
-
3
- module Moblues
4
- module Generator
5
- class Human < Base
6
- def generate(entity)
7
- write_header(entity) unless File.exists?(header_file(entity))
8
- write_implementation(entity) unless File.exists?(implementation_file(entity))
9
- end
10
-
11
- private
12
- def format_name(entity, extension)
13
- "#{entity.name}.#{extension}"
14
- end
15
-
16
- def header_template
17
- file_template('human_header.h')
18
- end
19
-
20
- def implementation_template
21
- file_template('human_implementation.m')
22
- end
23
- end
24
- end
25
- end
@@ -1,36 +0,0 @@
1
- require 'moblues/generator/base'
2
-
3
- module Moblues
4
- module Generator
5
- class Machine < Base
6
- def initialize(params)
7
- @type_reader = Reader::Type.new
8
- super(params)
9
- end
10
-
11
- def generate(entity)
12
- write_header(entity)
13
- write_implementation(entity)
14
- end
15
-
16
- private
17
- attr_reader :type_reader
18
-
19
- def format_name(entity, extension)
20
- "_#{entity.name}.#{extension}"
21
- end
22
-
23
- def capitalized_name(relationship)
24
- relationship.name.sub(/^./) { |first_character| first_character.upcase }
25
- end
26
-
27
- def header_template
28
- file_template('machine_header.h')
29
- end
30
-
31
- def implementation_template
32
- file_template('machine_implementation.m')
33
- end
34
- end
35
- end
36
- end
@@ -1,23 +0,0 @@
1
- require 'moblues/generator/machine'
2
- require 'moblues/generator/human'
3
-
4
- module Moblues
5
- module Generator
6
- class Model
7
- def initialize(params)
8
- @human = Human.new(output_dir: params.fetch(:human_dir))
9
- @machine = Machine.new(output_dir: params.fetch(:machine_dir))
10
- end
11
-
12
- def generate(entities)
13
- entities.each do |entity|
14
- human.generate(entity)
15
- machine.generate(entity)
16
- end
17
- end
18
-
19
- private
20
- attr_reader :human, :machine
21
- end
22
- end
23
- end
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
- require 'moblues/generator/human'
3
- require 'moblues/data_model'
4
-
5
- describe Moblues::Generator::Human do
6
- subject { described_class.new(output_dir: Fixtures.generated_dir) }
7
-
8
- after do
9
- Fixtures.delete_tmp_files(%w{Author.h Author.m})
10
- end
11
-
12
- describe '#generate' do
13
- it 'generates a human header' do
14
- subject.generate(entity)
15
-
16
- expect(Fixtures.generated_file_content('Author.h')).to eq(Fixtures.expected_content('Author.h'))
17
- end
18
-
19
- it 'generates a human implementation' do
20
- subject.generate(entity)
21
-
22
- expect(Fixtures.generated_file_content('Author.m')).to eq(Fixtures.expected_content('Author.m'))
23
- end
24
-
25
- context 'if the header already exists' do
26
- before do
27
- File.open(File.join(Fixtures.generated_dir, 'Author.h'), 'w+') do |f|
28
- f.write('do nothing')
29
- end
30
- end
31
-
32
- it 'does not overwrite the header file' do
33
- subject.generate(entity)
34
-
35
- expect(Fixtures.generated_file_content('Author.h')).to eq('do nothing')
36
- end
37
- end
38
-
39
- context 'if the implementation already exists' do
40
- before do
41
- File.open(File.join(Fixtures.generated_dir, 'Author.m'), 'w+') do |f|
42
- f.write('do nothing')
43
- end
44
- end
45
-
46
- it 'does not overwrite the implementation file' do
47
- subject.generate(entity)
48
-
49
- expect(Fixtures.generated_file_content('Author.m')).to eq('do nothing')
50
- end
51
- end
52
- end
53
-
54
- def entity
55
- Moblues::DataModel::Entity.new(name: 'Author',
56
- attributes: attributes,
57
- relationships: relationships)
58
- end
59
-
60
- def attributes
61
- [
62
- Moblues::DataModel::Attribute.new(name: 'dob', type: :date),
63
- Moblues::DataModel::Attribute.new(name: 'name', type: :string)
64
- ]
65
- end
66
-
67
- def relationships
68
- [
69
- Moblues::DataModel::Relationship.new(name: 'books', destination_entity: 'Book', to_many: true, ordered: true),
70
- Moblues::DataModel::Relationship.new(name: 'essays', destination_entity: 'Book', to_many: true),
71
- Moblues::DataModel::Relationship.new(name: 'publisher', destination_entity: 'Publisher')
72
- ]
73
- end
74
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Moblues::Generator::Model do
4
- describe '#generate' do
5
- subject { described_class.new(human: human, machine: machine, human_dir: human_dir, machine_dir: machine_dir) }
6
-
7
- let(:entities) { [build(:entity)] }
8
- let(:entity) { entities.first }
9
- let(:human_dir) { 'human/dir'}
10
- let(:machine_dir) { 'machine/dir'}
11
-
12
- let(:human) { double(Moblues::Generator::Human) }
13
- let(:machine) { double(Moblues::Generator::Machine) }
14
-
15
- before do
16
- allow(Moblues::Generator::Human).to receive(:new).with(output_dir: human_dir) { human }
17
- allow(Moblues::Generator::Machine).to receive(:new).with(output_dir: machine_dir) { machine }
18
- end
19
-
20
- it 'generates the human and machine files' do
21
- expect(human).to receive(:generate).with(entity).once
22
- expect(machine).to receive(:generate).with(entity).once
23
-
24
- subject.generate(entities)
25
- end
26
- end
27
- end
@@ -1,18 +0,0 @@
1
- #import <Foundation/Foundation.h>
2
- #import <CoreData/CoreData.h>
3
-
4
- @class Person;
5
-
6
- @interface _Team : NSManagedObject
7
-
8
- @property (nonatomic, strong) NSSet *teamMembers;
9
- @end
10
-
11
- @interface _Team (CoreDataGeneratedAccessors)
12
-
13
- - (void)addTeamMembersObject:(Person *)value;
14
- - (void)removeTeamMembersObject:(Person *)value;
15
- - (void)addTeamMembers:(NSSet *)values;
16
- - (void)removeTeamMembers:(NSSet *)values;
17
-
18
- @end
@@ -1,5 +0,0 @@
1
- #import "_Team.h"
2
-
3
- @implementation _Team
4
- @dynamic teamMembers;
5
- @end