wara 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +1 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +4 -0
  6. data/README.md +4 -0
  7. data/Rakefile +3 -0
  8. data/bin/wara +2 -1
  9. data/coredata/Model.xcdatamodeld/Model.xcdatamodel/contents +4 -4
  10. data/{out → coredata/ObjC}/_NotSameWrapper.h +2 -2
  11. data/{out → coredata/ObjC}/_NotSameWrapper.m +4 -4
  12. data/coredata/Swift/BloodPressureWrapper.swift +5 -0
  13. data/coredata/Swift/CurrentPersonWrapper.swift +5 -0
  14. data/coredata/Swift/HealthDataWrapper.swift +5 -0
  15. data/coredata/Swift/NotSameWrapper.swift +5 -0
  16. data/coredata/Swift/PersonWrapper.swift +5 -0
  17. data/coredata/Swift/_BloodPressureWrapper.swift +19 -0
  18. data/coredata/Swift/_CurrentPersonWrapper.swift +17 -0
  19. data/coredata/Swift/_HealthDataWrapper.swift +26 -0
  20. data/coredata/Swift/_NotSameWrapper.swift +50 -0
  21. data/coredata/Swift/_PersonWrapper.swift +23 -0
  22. data/lib/wara/version.rb +1 -1
  23. data/lib/wara.rb +82 -2
  24. data/spec/spec_helper.rb +11 -0
  25. data/spec/wara_spec.rb +55 -31
  26. metadata +34 -42
  27. data/coredata/_NotSameWrapper.h +0 -24
  28. data/coredata/_NotSameWrapper.m +0 -41
  29. data/out/BloodPressureWrapper.h +0 -5
  30. data/out/BloodPressureWrapper.m +0 -15
  31. data/out/CurrentPersonWrapper.h +0 -5
  32. data/out/CurrentPersonWrapper.m +0 -15
  33. data/out/HealthDataWrapper.h +0 -5
  34. data/out/HealthDataWrapper.m +0 -15
  35. data/out/NotSameWrapper.h +0 -5
  36. data/out/NotSameWrapper.m +0 -15
  37. data/out/PersonWrapper.h +0 -5
  38. data/out/PersonWrapper.m +0 -15
  39. data/out/_BloodPressureWrapper.h +0 -14
  40. data/out/_BloodPressureWrapper.m +0 -25
  41. data/out/_CurrentPersonWrapper.h +0 -13
  42. data/out/_CurrentPersonWrapper.m +0 -19
  43. data/out/_HealthDataWrapper.h +0 -16
  44. data/out/_HealthDataWrapper.m +0 -25
  45. data/out/_PersonWrapper.h +0 -15
  46. data/out/_PersonWrapper.m +0 -23
  47. /data/coredata/{BloodPressureWrapper.h → ObjC/BloodPressureWrapper.h} +0 -0
  48. /data/coredata/{BloodPressureWrapper.m → ObjC/BloodPressureWrapper.m} +0 -0
  49. /data/coredata/{CurrentPersonWrapper.h → ObjC/CurrentPersonWrapper.h} +0 -0
  50. /data/coredata/{CurrentPersonWrapper.m → ObjC/CurrentPersonWrapper.m} +0 -0
  51. /data/coredata/{HealthDataWrapper.h → ObjC/HealthDataWrapper.h} +0 -0
  52. /data/coredata/{HealthDataWrapper.m → ObjC/HealthDataWrapper.m} +0 -0
  53. /data/coredata/{NotSameWrapper.h → ObjC/NotSameWrapper.h} +0 -0
  54. /data/coredata/{NotSameWrapper.m → ObjC/NotSameWrapper.m} +0 -0
  55. /data/coredata/{PersonWrapper.h → ObjC/PersonWrapper.h} +0 -0
  56. /data/coredata/{PersonWrapper.m → ObjC/PersonWrapper.m} +0 -0
  57. /data/coredata/{_BloodPressureWrapper.h → ObjC/_BloodPressureWrapper.h} +0 -0
  58. /data/coredata/{_BloodPressureWrapper.m → ObjC/_BloodPressureWrapper.m} +0 -0
  59. /data/coredata/{_CurrentPersonWrapper.h → ObjC/_CurrentPersonWrapper.h} +0 -0
  60. /data/coredata/{_CurrentPersonWrapper.m → ObjC/_CurrentPersonWrapper.m} +0 -0
  61. /data/coredata/{_HealthDataWrapper.h → ObjC/_HealthDataWrapper.h} +0 -0
  62. /data/coredata/{_HealthDataWrapper.m → ObjC/_HealthDataWrapper.m} +0 -0
  63. /data/coredata/{_PersonWrapper.h → ObjC/_PersonWrapper.h} +0 -0
  64. /data/coredata/{_PersonWrapper.m → ObjC/_PersonWrapper.m} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67c6bd66035175ad19774976f3ca2e1c95b6c51b
4
- data.tar.gz: ad8320afd767ed39c1c1c81062dd47b38d6a5bab
3
+ metadata.gz: 4774a99b9a89f626eec2f586897780426b599d60
4
+ data.tar.gz: 7f85f7cf5768377fd354a512c0b9ad3334e41ab3
5
5
  SHA512:
6
- metadata.gz: 236437542b04c9e6e211531f6ed8d45252cbf5d74b04a7bd30639f6c7fe330fbb59a3e83166bff7dd47e162ad9f4f1c5a45e83830c9a84f9ba5a36c78ec261c6
7
- data.tar.gz: d1fb17ca78b750e2d4554d842ac39e36bf7299d0d2da9f526199ee67b0f0b83542c1bdc14a266eb246b9cefebf2f2cdae279fcef9f4d2c1fc1672a52c2c451d9
6
+ metadata.gz: 83710cc9081a2214c14c0917bed92fa9c68043b9da40839f21e2af433f29e81436428a3accfc6cf64c69b2fb176752ec61425dd05eaa5273ec183e95ba300e46
7
+ data.tar.gz: d08443138f5b3b8d39683b6954222c33a2622ea33e73d3bed40612e999535a621780d1dbfb6a23236dba146a8bb8e8efcb8e2b324fab51879de9b364a9a2f1b4
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ out
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile CHANGED
@@ -4,3 +4,7 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
  gem "rspec", "~> 2.14.1"
6
6
  gem "thor", "~> 0.18.1"
7
+
8
+ group :test do
9
+ gem 'coveralls', :require => false
10
+ end
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Wara
2
2
 
3
+ [![Build Status](https://travis-ci.org/akuraru/Wara.svg?branch=master)](https://travis-ci.org/akuraru/Wara)
4
+ [![Coverage Status](https://coveralls.io/repos/akuraru/Wara/badge.png?branch=master)](https://coveralls.io/r/akuraru/Wara?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/akuraru/Wara/badges/gpa.svg)](https://codeclimate.com/github/akuraru/Wara)
6
+
3
7
  Wara generate a scapegoat for objects of CoreData.
4
8
 
5
9
  You are using CoreDate, if you want to change the Entity, it is necessary to create a sub-context.However, it takes time be used to manage the sub-context.On the other hand, it is necessary to undo to the default context if one context.
data/Rakefile CHANGED
@@ -1,2 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
4
+ RSpec::Core::RakeTask.new("spec")
5
+ task default: :spec
data/bin/wara CHANGED
@@ -11,9 +11,10 @@ module Wara
11
11
 
12
12
  option :model, :type => :string, :aliases => '-m',:required => true, :desc => 'Path to model'
13
13
  option :out, :type => :string, :aliases => '-o', :desc => 'Output directory'
14
+ option :swift, :type => :boolean, :desc => 'Generate Swift'
14
15
  desc "create", "create Translation.strings"
15
16
  def create
16
- Wara::Core.new.create(options[:model], options[:out])
17
+ Wara::Core.new.create(options[:model], options[:out], options[:swift] ? Lang::ObjC : Lang::Swift)
17
18
  puts 'Generate'
18
19
  end
19
20
  desc "version", "version"
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
- <model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="6220.17" systemVersion="13E28" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
2
+ <model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="6244" systemVersion="13F34" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
3
3
  <entity name="BloodPressure" representedClassName="BloodPressure" parentEntity="HealthData" syncable="YES">
4
4
  <attribute name="bloodPressure" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
5
5
  </entity>
@@ -18,8 +18,8 @@
18
18
  <attribute name="data" optional="YES" attributeType="Binary" syncable="YES"/>
19
19
  <attribute name="date" optional="YES" attributeType="Date" syncable="YES"/>
20
20
  <attribute name="decimal" optional="YES" attributeType="Decimal" defaultValueString="0.0" syncable="YES"/>
21
- <attribute name="double" optional="YES" attributeType="Double" defaultValueString="0.0" syncable="YES"/>
22
- <attribute name="float" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES"/>
21
+ <attribute name="dou" optional="YES" attributeType="Double" defaultValueString="0.0" syncable="YES"/>
22
+ <attribute name="flo" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES"/>
23
23
  <attribute name="int16" optional="YES" attributeType="Integer 16" defaultValueString="0" syncable="YES"/>
24
24
  <attribute name="int32" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
25
25
  <attribute name="int64" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
@@ -36,8 +36,8 @@
36
36
  <element name="BloodPressure" positionX="-27" positionY="63" width="128" height="60"/>
37
37
  <element name="CurrentPerson" positionX="-63" positionY="-18" width="128" height="60"/>
38
38
  <element name="HealthData" positionX="-36" positionY="9" width="128" height="105"/>
39
- <element name="Person" positionX="-54" positionY="-9" width="128" height="105"/>
40
39
  <element name="NotHaveCusttomClassName" positionX="-54" positionY="36" width="128" height="43"/>
41
40
  <element name="NotSameCusstomClassName" positionX="-45" positionY="45" width="128" height="210"/>
41
+ <element name="Person" positionX="-54" positionY="-9" width="128" height="105"/>
42
42
  </elements>
43
43
  </model>
@@ -8,8 +8,8 @@
8
8
  @property(nonatomic, strong) NSData *data;
9
9
  @property(nonatomic, strong) NSDate *date;
10
10
  @property(nonatomic, strong) NSDecimalNumber *decimal;
11
- @property(nonatomic, strong) NSNumber *double;
12
- @property(nonatomic, strong) NSNumber *float;
11
+ @property(nonatomic, strong) NSNumber *dou;
12
+ @property(nonatomic, strong) NSNumber *flo;
13
13
  @property(nonatomic, strong) NSNumber *int16;
14
14
  @property(nonatomic, strong) NSNumber *int32;
15
15
  @property(nonatomic, strong) NSNumber *int64;
@@ -14,8 +14,8 @@
14
14
  self.data = entity.data;
15
15
  self.date = entity.date;
16
16
  self.decimal = entity.decimal;
17
- self.double = entity.double;
18
- self.float = entity.float;
17
+ self.dou = entity.dou;
18
+ self.flo = entity.flo;
19
19
  self.int16 = entity.int16;
20
20
  self.int32 = entity.int32;
21
21
  self.int64 = entity.int64;
@@ -30,8 +30,8 @@
30
30
  entity.data = self.data;
31
31
  entity.date = self.date;
32
32
  entity.decimal = self.decimal;
33
- entity.double = self.double;
34
- entity.float = self.float;
33
+ entity.dou = self.dou;
34
+ entity.flo = self.flo;
35
35
  entity.int16 = self.int16;
36
36
  entity.int32 = self.int32;
37
37
  entity.int64 = self.int64;
@@ -0,0 +1,5 @@
1
+ import Foundation
2
+
3
+ class BloodPressureWrapper: _BloodPressureWrapper {
4
+ // Custom logic goes here.
5
+ }
@@ -0,0 +1,5 @@
1
+ import Foundation
2
+
3
+ class CurrentPersonWrapper: _CurrentPersonWrapper {
4
+ // Custom logic goes here.
5
+ }
@@ -0,0 +1,5 @@
1
+ import Foundation
2
+
3
+ class HealthDataWrapper: _HealthDataWrapper {
4
+ // Custom logic goes here.
5
+ }
@@ -0,0 +1,5 @@
1
+ import Foundation
2
+
3
+ class NotSameWrapper: _NotSameWrapper {
4
+ // Custom logic goes here.
5
+ }
@@ -0,0 +1,5 @@
1
+ import Foundation
2
+
3
+ class PersonWrapper: _PersonWrapper {
4
+ // Custom logic goes here.
5
+ }
@@ -0,0 +1,19 @@
1
+ import Foundation
2
+
3
+ class _BloodPressureWrapper: HealthDataWrapper {
4
+ override func entity() -> BloodPressure? {
5
+ return _entity as BloodPressure?
6
+ }
7
+ var bloodPressure: NSNumber?
8
+
9
+ init(bloodPressure: BloodPressure?) {
10
+ super.init(healthData: bloodPressure)
11
+ if let e = bloodPressure {
12
+ self.bloodPressure = e.bloodPressure
13
+ }
14
+ }
15
+ func updateBloodPressure(bloodPressure: BloodPressure) {
16
+ super.updateHealthData(bloodPressure)
17
+ bloodPressure.bloodPressure = self.bloodPressure
18
+ }
19
+ }
@@ -0,0 +1,17 @@
1
+ import Foundation
2
+
3
+ class _CurrentPersonWrapper: NSObject {
4
+ let _entity: CurrentPerson?
5
+ func entity() -> CurrentPerson? {
6
+ return _entity
7
+ }
8
+
9
+ init(currentPerson: CurrentPerson?) {
10
+ _entity = currentPerson
11
+ super.init()
12
+ if let e = currentPerson {
13
+ }
14
+ }
15
+ func updateCurrentPerson(currentPerson: CurrentPerson) {
16
+ }
17
+ }
@@ -0,0 +1,26 @@
1
+ import Foundation
2
+
3
+ class _HealthDataWrapper: NSObject {
4
+ let _entity: HealthData?
5
+ func entity() -> HealthData? {
6
+ return _entity
7
+ }
8
+ var height: NSNumber?
9
+ var timeStamp: NSDate?
10
+ var weight: NSNumber?
11
+
12
+ init(healthData: HealthData?) {
13
+ _entity = healthData
14
+ super.init()
15
+ if let e = healthData {
16
+ self.height = e.height
17
+ self.timeStamp = e.timeStamp
18
+ self.weight = e.weight
19
+ }
20
+ }
21
+ func updateHealthData(healthData: HealthData) {
22
+ healthData.height = self.height
23
+ healthData.timeStamp = self.timeStamp
24
+ healthData.weight = self.weight
25
+ }
26
+ }
@@ -0,0 +1,50 @@
1
+ import Foundation
2
+
3
+ class _NotSameWrapper: NSObject {
4
+ let _entity: NotSame?
5
+ func entity() -> NotSame? {
6
+ return _entity
7
+ }
8
+ var boolean: NSNumber?
9
+ var data: NSData?
10
+ var date: NSDate?
11
+ var decimal: NSDecimalNumber?
12
+ var dou: NSNumber?
13
+ var flo: NSNumber?
14
+ var int16: NSNumber?
15
+ var int32: NSNumber?
16
+ var int64: NSNumber?
17
+ var string: String?
18
+ var transformable: AnyObject?
19
+
20
+ init(notSame: NotSame?) {
21
+ _entity = notSame
22
+ super.init()
23
+ if let e = notSame {
24
+ self.boolean = e.boolean
25
+ self.data = e.data
26
+ self.date = e.date
27
+ self.decimal = e.decimal
28
+ self.dou = e.dou
29
+ self.flo = e.flo
30
+ self.int16 = e.int16
31
+ self.int32 = e.int32
32
+ self.int64 = e.int64
33
+ self.string = e.string
34
+ self.transformable = e.transformable
35
+ }
36
+ }
37
+ func updateNotSame(notSame: NotSame) {
38
+ notSame.boolean = self.boolean
39
+ notSame.data = self.data
40
+ notSame.date = self.date
41
+ notSame.decimal = self.decimal
42
+ notSame.dou = self.dou
43
+ notSame.flo = self.flo
44
+ notSame.int16 = self.int16
45
+ notSame.int32 = self.int32
46
+ notSame.int64 = self.int64
47
+ notSame.string = self.string
48
+ notSame.transformable = self.transformable
49
+ }
50
+ }
@@ -0,0 +1,23 @@
1
+ import Foundation
2
+
3
+ class _PersonWrapper: NSObject {
4
+ let _entity: Person?
5
+ func entity() -> Person? {
6
+ return _entity
7
+ }
8
+ var birthday: NSDate?
9
+ var name: String?
10
+
11
+ init(person: Person?) {
12
+ _entity = person
13
+ super.init()
14
+ if let e = person {
15
+ self.birthday = e.birthday
16
+ self.name = e.name
17
+ }
18
+ }
19
+ func updatePerson(person: Person) {
20
+ person.birthday = self.birthday
21
+ person.name = self.name
22
+ }
23
+ }
data/lib/wara/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wara
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/wara.rb CHANGED
@@ -3,9 +3,33 @@ require 'kconv'
3
3
  require 'fileutils'
4
4
  require 'rexml/document'
5
5
 
6
+ class String
7
+ def to_snake
8
+ ptn = /[A-Z\s]*[^A-Z]*/
9
+ self.scan(ptn).map{|i|
10
+ i.gsub(/[\s:]+/,'_').downcase
11
+ }.join('_').gsub(/__+/,'_').sub(/_$/,'')
12
+ end
13
+ def to_camel
14
+ self.split(/[_\s]+/).map{|i|
15
+ a,b,c = i.split(/^(.)/)
16
+ "#{b.upcase}#{c}"
17
+ }.join('')
18
+ end
19
+ def to_scamel
20
+ s = self.to_camel
21
+ s[0].downcase + s[1..-1]
22
+ end
23
+ end
24
+
6
25
  module Wara
26
+ module Lang
27
+ ObjC = 0
28
+ Swift = 1
29
+ end
30
+
7
31
  class Core
8
- def create(model, to)
32
+ def create(model, to, lang = Lang::ObjC)
9
33
  to = File.dirname(model) unless to
10
34
  @xml = REXML::Document.new(open(File.expand_path("contents", model)))
11
35
  @objects = @xml.get_elements('model/entity')
@@ -22,8 +46,18 @@ module Wara
22
46
  },
23
47
  }
24
48
  }.select{|s| s["representedClassName"]}
49
+ output(@entities, to, lang)
50
+ end
51
+ def output(entities, to, lang)
25
52
  FileUtils.mkdir_p(to) unless FileTest.exist?(to)
26
- @entities.map {|e|
53
+ if lang == Lang::ObjC then
54
+ output_objc(entities, to)
55
+ else
56
+ output_swift(entities, to)
57
+ end
58
+ end
59
+ def output_objc(entities, to)
60
+ entities.map {|e|
27
61
  file_name = e["representedClassName"]
28
62
  hw = header(e)
29
63
  File.write( File.expand_path("_#{file_name}Wrapper.h", to), hw)
@@ -35,6 +69,15 @@ module Wara
35
69
  File.write( custom_implementation_name, custom_implementation(file_name)) unless FileTest.exist?(custom_implementation_name)
36
70
  }
37
71
  end
72
+ def output_swift(entities, to)
73
+ entities.map {|e|
74
+ file_name = e["representedClassName"]
75
+ mw = swift(e)
76
+ File.write( File.expand_path("_#{file_name}Wrapper.swift", to), mw)
77
+ custom_implementation_name = File.expand_path("#{file_name}Wrapper.swift", to)
78
+ File.write( custom_implementation_name, custom_swift(file_name)) unless FileTest.exist?(custom_implementation_name)
79
+ }
80
+ end
38
81
  def header(e)
39
82
  name = e["representedClassName"]
40
83
  entity = e["parentEntity"]
@@ -81,5 +124,42 @@ module Wara
81
124
  "Transformable"=>"id ",
82
125
  }[value]
83
126
  end
127
+ def swift(e)
128
+ name = e["representedClassName"]
129
+ entity = e["parentEntity"]
130
+ init = entity ? "[super initWithEntity:entity]" : "[super init]"
131
+ parentEntity = entity ? ": #{entity}Wrapper" : ": NSObject"
132
+ getter = entity ? " override func entity() -> #{name}? {\n return _entity as #{name}?\n" : " let _entity: #{name}?\n func entity() -> #{name}? {\n return _entity\n"
133
+ init = entity ? " super.init(#{entity.to_scamel}: #{name.to_scamel})\n" : " _entity = #{name.to_scamel}\n super.init()\n"
134
+ update = entity ? " super.update#{entity}(#{name.to_scamel})\n" : ""
135
+ "import Foundation\n\nclass _#{name}Wrapper#{parentEntity} {\n#{getter} }\n" +
136
+ e["attributes"].map {|k, v|
137
+ " " * 4 + "var #{k}: #{entitySwiftType(v)}\n"
138
+ }.inject("") {|s, v| s + v} + "\n init(#{name.to_scamel}: #{name}?) {\n#{init} if let e = #{name.to_scamel} {\n" +
139
+ e["attributes"].map {|k, v|
140
+ " " * 12 + "self.#{k} = e.#{k}\n"
141
+ }.inject("") {|s, v| s + v} + " }\n }\n func update#{name}(#{name.to_scamel}: #{name}) {\n#{update}" +
142
+ e["attributes"].map {|k, v|
143
+ " " * 8 + "#{name.to_scamel}.#{k} = self.#{k}\n"
144
+ }.inject("") {|s, v| s + v} + " }\n}\n"
145
+ end
146
+ def custom_swift(file_name)
147
+ "import Foundation\n\nclass #{file_name}Wrapper: _#{file_name}Wrapper {\n // Custom logic goes here.\n}\n"
148
+ end
149
+ def entitySwiftType(value)
150
+ {
151
+ "Boolean"=>"NSNumber?",
152
+ "Binary"=>"NSData?",
153
+ "Date"=>"NSDate?",
154
+ "Decimal"=>"NSDecimalNumber?",
155
+ "Double"=>"NSNumber?",
156
+ "Float"=>"NSNumber?",
157
+ "Integer 16"=>"NSNumber?",
158
+ "Integer 32"=>"NSNumber?",
159
+ "Integer 64"=>"NSNumber?",
160
+ "String"=>"String?",
161
+ "Transformable"=>"AnyObject?",
162
+ }[value]
163
+ end
84
164
  end
85
165
  end
data/spec/spec_helper.rb CHANGED
@@ -14,6 +14,17 @@
14
14
  # users commonly want.
15
15
  #
16
16
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ require 'coveralls'
18
+ Coveralls.wear!
19
+
20
+
21
+ require 'simplecov'
22
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
23
+ SimpleCov::Formatter::HTMLFormatter,
24
+ Coveralls::SimpleCov::Formatter
25
+ ]
26
+ SimpleCov.start
27
+
17
28
  RSpec.configure do |config|
18
29
  # The settings below are suggested to provide a good initial experience
19
30
  # with RSpec, but feel free to customize to your heart's content.
data/spec/wara_spec.rb CHANGED
@@ -1,6 +1,13 @@
1
+ require 'spec_helper'
1
2
  require './lib/wara'
2
3
  require 'fileutils'
3
4
 
5
+ describe String do
6
+ it(:to_snake) { expect("HogeFuga".to_snake).to eq "hoge_fuga"}
7
+ it(:to_camel) { expect("hoge_fuga".to_camel).to eq "HogeFuga" }
8
+ it(:to_scamel) { expect("hoge_fuga".to_scamel).to eq "hogeFuga" }
9
+ end
10
+
4
11
  module Wara
5
12
  class Core
6
13
  attr_reader :xml, :objects, :entities
@@ -8,17 +15,28 @@ module Wara
8
15
  end
9
16
 
10
17
  describe Wara::Core, "load" do
11
- let(:core) {Wara::Core.new() }
12
18
  entity_names = ["BloodPressure", "HealthData", "CurrentPerson", "NotSame", "Person"]
13
- describe "creaet" do
19
+ shared_context 'delete all file' do
14
20
  before do
15
- entity_names.each {|n|
16
- Dir["./out/*.*"].each {|n|
17
- File.delete(n)
18
- }
21
+ Dir["./out/ObjC/*.*"].each {|f|
22
+ File.delete(f)
23
+ }
24
+ Dir["./out/Swift/*.*"].each {|f|
25
+ File.delete(f)
19
26
  }
20
- core.create("./coredata/Model.xcdatamodeld/Model.xcdatamodel", "./out")
21
27
  end
28
+ end
29
+ shared_context 'create' do
30
+ let(:core) {Wara::Core.new() }
31
+ before do
32
+ core.create("./coredata/Model.xcdatamodeld/Model.xcdatamodel", out, lang)
33
+ end
34
+ end
35
+ describe "creaet" do
36
+ let(:out) { "./out/ObjC" }
37
+ let(:lang) { Wara::Lang::ObjC }
38
+ include_context 'delete all file'
39
+ include_context 'create'
22
40
  describe "xml" do
23
41
  let(:xml) { core.xml }
24
42
  it(:create) {
@@ -71,7 +89,7 @@ describe Wara::Core, "load" do
71
89
  it(:check_3) {
72
90
  expect(entities[3]).to eq(
73
91
  {
74
- "attributes" => {"boolean"=>"Boolean", "data"=>"Binary", "date"=>"Date", "decimal"=>"Decimal", "double"=>"Double", "float"=>"Float", "int16"=>"Integer 16", "int32"=>"Integer 32", "int64"=>"Integer 64", "string"=>"String", "transformable"=>"Transformable"},
92
+ "attributes" => {"boolean"=>"Boolean", "data"=>"Binary", "date"=>"Date", "decimal"=>"Decimal", "dou"=>"Double", "flo"=>"Float", "int16"=>"Integer 16", "int32"=>"Integer 32", "int64"=>"Integer 64", "string"=>"String", "transformable"=>"Transformable"},
75
93
  "name"=>"NotSameCusstomClassName",
76
94
  "representedClassName"=>"NotSame",
77
95
  "parentEntity"=>nil,
@@ -87,33 +105,39 @@ describe Wara::Core, "load" do
87
105
  } )
88
106
  }
89
107
  end
108
+ end
109
+ describe(:objc) {
110
+ let(:dir) { "ObjC/" }
111
+ let(:out) { "./out/#{dir}" }
112
+ let(:input) { "./coredata/#{dir}" }
113
+ let(:lang) { Wara::Lang::ObjC }
114
+ include_context 'delete all file'
115
+ include_context 'create'
90
116
  entity_names.each {|e|
91
- describe(:read_interface) {
92
- let(:read_interface) { File.read("out/_#{e}Wrapper.h")}
93
- let(:expected) { File.read("coredata/_#{e}Wrapper.h")}
94
- it(e) { expect(read_interface).to eq expected }
95
- }
96
- }
97
- entity_names.each {|e|
98
- describe(:read_implementation) {
99
- let(:read_implementation) { File.read("out/_#{e}Wrapper.m")}
100
- let(:expected) { File.read("coredata/_#{e}Wrapper.m")}
101
- it(e) { expect(read_implementation).to eq expected }
102
- }
103
- }
104
- entity_names.each {|e|
105
- describe(:read_interface_name) {
106
- let(:read_interface_name) { File.read("out/#{e}Wrapper.h")}
107
- let(:expected) { File.read("coredata/#{e}Wrapper.h")}
108
- it(e) { expect(read_interface_name).to eq expected }
117
+ ["_#{e}Wrapper.h", "_#{e}Wrapper.m", "#{e}Wrapper.h", "#{e}Wrapper.m"].each {|file_name|
118
+ describe(file_name) {
119
+ let(:read_interface) { File.read("#{out}#{file_name}")}
120
+ let(:expected) { File.read("#{input}#{file_name}")}
121
+ it(e) { expect(read_interface).to eq expected }
122
+ }
109
123
  }
110
124
  }
125
+ }
126
+ describe(:objc) {
127
+ let(:dir) { "Swift/" }
128
+ let(:out) { "./out/#{dir}" }
129
+ let(:input) { "./coredata/#{dir}" }
130
+ let(:lang) { Wara::Lang::Swift }
131
+ include_context 'delete all file'
132
+ include_context 'create'
111
133
  entity_names.each {|e|
112
- describe(:read_implementation_name) {
113
- let(:read_implementation_name) { File.read("out/#{e}Wrapper.m")}
114
- let(:expected) { File.read("coredata/#{e}Wrapper.m")}
115
- it(e) { expect(read_implementation_name).to eq expected }
134
+ ["_#{e}Wrapper.swift", "#{e}Wrapper.swift"].each {|file_name|
135
+ describe(file_name) {
136
+ let(:read_interface) { File.read("#{out}#{file_name}")}
137
+ let(:expected) { File.read("#{input}#{file_name}")}
138
+ it(e) { expect(read_interface).to eq expected }
139
+ }
116
140
  }
117
141
  }
118
- end
142
+ }
119
143
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wara
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - akuraru
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-19 00:00:00.000000000 Z
11
+ date: 2014-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -65,55 +65,47 @@ executables:
65
65
  extensions: []
66
66
  extra_rdoc_files: []
67
67
  files:
68
+ - ".coveralls.yml"
68
69
  - ".gitignore"
70
+ - ".travis.yml"
69
71
  - Gemfile
70
72
  - LICENSE.txt
71
73
  - README.md
72
74
  - Rakefile
73
75
  - bin/wara
74
- - coredata/BloodPressureWrapper.h
75
- - coredata/BloodPressureWrapper.m
76
- - coredata/CurrentPersonWrapper.h
77
- - coredata/CurrentPersonWrapper.m
78
- - coredata/HealthDataWrapper.h
79
- - coredata/HealthDataWrapper.m
80
76
  - coredata/Model.xcdatamodeld/Model.xcdatamodel/contents
81
- - coredata/NotSameWrapper.h
82
- - coredata/NotSameWrapper.m
83
- - coredata/PersonWrapper.h
84
- - coredata/PersonWrapper.m
85
- - coredata/_BloodPressureWrapper.h
86
- - coredata/_BloodPressureWrapper.m
87
- - coredata/_CurrentPersonWrapper.h
88
- - coredata/_CurrentPersonWrapper.m
89
- - coredata/_HealthDataWrapper.h
90
- - coredata/_HealthDataWrapper.m
91
- - coredata/_NotSameWrapper.h
92
- - coredata/_NotSameWrapper.m
93
- - coredata/_PersonWrapper.h
94
- - coredata/_PersonWrapper.m
77
+ - coredata/ObjC/BloodPressureWrapper.h
78
+ - coredata/ObjC/BloodPressureWrapper.m
79
+ - coredata/ObjC/CurrentPersonWrapper.h
80
+ - coredata/ObjC/CurrentPersonWrapper.m
81
+ - coredata/ObjC/HealthDataWrapper.h
82
+ - coredata/ObjC/HealthDataWrapper.m
83
+ - coredata/ObjC/NotSameWrapper.h
84
+ - coredata/ObjC/NotSameWrapper.m
85
+ - coredata/ObjC/PersonWrapper.h
86
+ - coredata/ObjC/PersonWrapper.m
87
+ - coredata/ObjC/_BloodPressureWrapper.h
88
+ - coredata/ObjC/_BloodPressureWrapper.m
89
+ - coredata/ObjC/_CurrentPersonWrapper.h
90
+ - coredata/ObjC/_CurrentPersonWrapper.m
91
+ - coredata/ObjC/_HealthDataWrapper.h
92
+ - coredata/ObjC/_HealthDataWrapper.m
93
+ - coredata/ObjC/_NotSameWrapper.h
94
+ - coredata/ObjC/_NotSameWrapper.m
95
+ - coredata/ObjC/_PersonWrapper.h
96
+ - coredata/ObjC/_PersonWrapper.m
97
+ - coredata/Swift/BloodPressureWrapper.swift
98
+ - coredata/Swift/CurrentPersonWrapper.swift
99
+ - coredata/Swift/HealthDataWrapper.swift
100
+ - coredata/Swift/NotSameWrapper.swift
101
+ - coredata/Swift/PersonWrapper.swift
102
+ - coredata/Swift/_BloodPressureWrapper.swift
103
+ - coredata/Swift/_CurrentPersonWrapper.swift
104
+ - coredata/Swift/_HealthDataWrapper.swift
105
+ - coredata/Swift/_NotSameWrapper.swift
106
+ - coredata/Swift/_PersonWrapper.swift
95
107
  - lib/wara.rb
96
108
  - lib/wara/version.rb
97
- - out/BloodPressureWrapper.h
98
- - out/BloodPressureWrapper.m
99
- - out/CurrentPersonWrapper.h
100
- - out/CurrentPersonWrapper.m
101
- - out/HealthDataWrapper.h
102
- - out/HealthDataWrapper.m
103
- - out/NotSameWrapper.h
104
- - out/NotSameWrapper.m
105
- - out/PersonWrapper.h
106
- - out/PersonWrapper.m
107
- - out/_BloodPressureWrapper.h
108
- - out/_BloodPressureWrapper.m
109
- - out/_CurrentPersonWrapper.h
110
- - out/_CurrentPersonWrapper.m
111
- - out/_HealthDataWrapper.h
112
- - out/_HealthDataWrapper.m
113
- - out/_NotSameWrapper.h
114
- - out/_NotSameWrapper.m
115
- - out/_PersonWrapper.h
116
- - out/_PersonWrapper.m
117
109
  - spec/spec_helper.rb
118
110
  - spec/wara_spec.rb
119
111
  - wara.gemspec
@@ -1,24 +0,0 @@
1
- #import <Foundation/Foundation.h>
2
-
3
- @class NotSame;
4
-
5
-
6
- @interface _NotSameWrapper : NSObject
7
- @property(nonatomic, strong) NSNumber *boolean;
8
- @property(nonatomic, strong) NSData *data;
9
- @property(nonatomic, strong) NSDate *date;
10
- @property(nonatomic, strong) NSDecimalNumber *decimal;
11
- @property(nonatomic, strong) NSNumber *double;
12
- @property(nonatomic, strong) NSNumber *float;
13
- @property(nonatomic, strong) NSNumber *int16;
14
- @property(nonatomic, strong) NSNumber *int32;
15
- @property(nonatomic, strong) NSNumber *int64;
16
- @property(nonatomic, strong) NSString *string;
17
- @property(nonatomic, strong) id transformable;
18
-
19
- @property(readonly, strong, nonatomic) NotSame *entity;
20
-
21
- - (instancetype)initWithEntity:(NotSame *)entity;
22
-
23
- - (void)updateEntity:(NotSame *)entity;
24
- @end
@@ -1,41 +0,0 @@
1
- #import "_NotSameWrapper.h"
2
- #import "NotSame.h"
3
-
4
- @interface _NotSameWrapper ()
5
- @end
6
-
7
- @implementation _NotSameWrapper {
8
- }
9
- - (instancetype)initWithEntity:(NotSame *)entity {
10
- self = [super init];
11
- if (self) {
12
- _entity = entity;
13
- self.boolean = entity.boolean;
14
- self.data = entity.data;
15
- self.date = entity.date;
16
- self.decimal = entity.decimal;
17
- self.double = entity.double;
18
- self.float = entity.float;
19
- self.int16 = entity.int16;
20
- self.int32 = entity.int32;
21
- self.int64 = entity.int64;
22
- self.string = entity.string;
23
- self.transformable = entity.transformable;
24
- }
25
- return self;
26
- }
27
-
28
- - (void)updateEntity:(NotSame *)entity {
29
- entity.boolean = self.boolean;
30
- entity.data = self.data;
31
- entity.date = self.date;
32
- entity.decimal = self.decimal;
33
- entity.double = self.double;
34
- entity.float = self.float;
35
- entity.int16 = self.int16;
36
- entity.int32 = self.int32;
37
- entity.int64 = self.int64;
38
- entity.string = self.string;
39
- entity.transformable = self.transformable;
40
- }
41
- @end
@@ -1,5 +0,0 @@
1
- #import "_BloodPressureWrapper.h"
2
-
3
- @interface BloodPressureWrapper : _BloodPressureWrapper {}
4
- // Custom logic goes here.
5
- @end
@@ -1,15 +0,0 @@
1
- #import "BloodPressureWrapper.h"
2
-
3
-
4
- @interface BloodPressureWrapper ()
5
-
6
- // Private interface goes here.
7
-
8
- @end
9
-
10
-
11
- @implementation BloodPressureWrapper
12
-
13
- // Custom logic goes here.
14
-
15
- @end
@@ -1,5 +0,0 @@
1
- #import "_CurrentPersonWrapper.h"
2
-
3
- @interface CurrentPersonWrapper : _CurrentPersonWrapper {}
4
- // Custom logic goes here.
5
- @end
@@ -1,15 +0,0 @@
1
- #import "CurrentPersonWrapper.h"
2
-
3
-
4
- @interface CurrentPersonWrapper ()
5
-
6
- // Private interface goes here.
7
-
8
- @end
9
-
10
-
11
- @implementation CurrentPersonWrapper
12
-
13
- // Custom logic goes here.
14
-
15
- @end
@@ -1,5 +0,0 @@
1
- #import "_HealthDataWrapper.h"
2
-
3
- @interface HealthDataWrapper : _HealthDataWrapper {}
4
- // Custom logic goes here.
5
- @end
@@ -1,15 +0,0 @@
1
- #import "HealthDataWrapper.h"
2
-
3
-
4
- @interface HealthDataWrapper ()
5
-
6
- // Private interface goes here.
7
-
8
- @end
9
-
10
-
11
- @implementation HealthDataWrapper
12
-
13
- // Custom logic goes here.
14
-
15
- @end
data/out/NotSameWrapper.h DELETED
@@ -1,5 +0,0 @@
1
- #import "_NotSameWrapper.h"
2
-
3
- @interface NotSameWrapper : _NotSameWrapper {}
4
- // Custom logic goes here.
5
- @end
data/out/NotSameWrapper.m DELETED
@@ -1,15 +0,0 @@
1
- #import "NotSameWrapper.h"
2
-
3
-
4
- @interface NotSameWrapper ()
5
-
6
- // Private interface goes here.
7
-
8
- @end
9
-
10
-
11
- @implementation NotSameWrapper
12
-
13
- // Custom logic goes here.
14
-
15
- @end
data/out/PersonWrapper.h DELETED
@@ -1,5 +0,0 @@
1
- #import "_PersonWrapper.h"
2
-
3
- @interface PersonWrapper : _PersonWrapper {}
4
- // Custom logic goes here.
5
- @end
data/out/PersonWrapper.m DELETED
@@ -1,15 +0,0 @@
1
- #import "PersonWrapper.h"
2
-
3
-
4
- @interface PersonWrapper ()
5
-
6
- // Private interface goes here.
7
-
8
- @end
9
-
10
-
11
- @implementation PersonWrapper
12
-
13
- // Custom logic goes here.
14
-
15
- @end
@@ -1,14 +0,0 @@
1
- #import "HealthDataWrapper.h"
2
-
3
- @class BloodPressure;
4
-
5
-
6
- @interface _BloodPressureWrapper : HealthDataWrapper
7
- @property(nonatomic, strong) NSNumber *bloodPressure;
8
-
9
- - (BloodPressure *)entity;
10
-
11
- - (instancetype)initWithEntity:(BloodPressure *)entity;
12
-
13
- - (void)updateEntity:(BloodPressure *)entity;
14
- @end
@@ -1,25 +0,0 @@
1
- #import "_BloodPressureWrapper.h"
2
- #import "BloodPressure.h"
3
-
4
- @interface _BloodPressureWrapper ()
5
- @end
6
-
7
- @implementation _BloodPressureWrapper {
8
- }
9
- - (BloodPressure *)entity {
10
- return (BloodPressure *) [super entity];
11
- }
12
-
13
- - (instancetype)initWithEntity:(BloodPressure *)entity {
14
- self = [super initWithEntity:entity];
15
- if (self) {
16
- self.bloodPressure = entity.bloodPressure;
17
- }
18
- return self;
19
- }
20
-
21
- - (void)updateEntity:(BloodPressure *)entity {
22
- [super updateEntity:entity];
23
- entity.bloodPressure = self.bloodPressure;
24
- }
25
- @end
@@ -1,13 +0,0 @@
1
- #import <Foundation/Foundation.h>
2
-
3
- @class CurrentPerson;
4
-
5
-
6
- @interface _CurrentPersonWrapper : NSObject
7
-
8
- @property(readonly, strong, nonatomic) CurrentPerson *entity;
9
-
10
- - (instancetype)initWithEntity:(CurrentPerson *)entity;
11
-
12
- - (void)updateEntity:(CurrentPerson *)entity;
13
- @end
@@ -1,19 +0,0 @@
1
- #import "_CurrentPersonWrapper.h"
2
- #import "CurrentPerson.h"
3
-
4
- @interface _CurrentPersonWrapper ()
5
- @end
6
-
7
- @implementation _CurrentPersonWrapper {
8
- }
9
- - (instancetype)initWithEntity:(CurrentPerson *)entity {
10
- self = [super init];
11
- if (self) {
12
- _entity = entity;
13
- }
14
- return self;
15
- }
16
-
17
- - (void)updateEntity:(CurrentPerson *)entity {
18
- }
19
- @end
@@ -1,16 +0,0 @@
1
- #import <Foundation/Foundation.h>
2
-
3
- @class HealthData;
4
-
5
-
6
- @interface _HealthDataWrapper : NSObject
7
- @property(nonatomic, strong) NSNumber *height;
8
- @property(nonatomic, strong) NSDate *timeStamp;
9
- @property(nonatomic, strong) NSNumber *weight;
10
-
11
- @property(readonly, strong, nonatomic) HealthData *entity;
12
-
13
- - (instancetype)initWithEntity:(HealthData *)entity;
14
-
15
- - (void)updateEntity:(HealthData *)entity;
16
- @end
@@ -1,25 +0,0 @@
1
- #import "_HealthDataWrapper.h"
2
- #import "HealthData.h"
3
-
4
- @interface _HealthDataWrapper ()
5
- @end
6
-
7
- @implementation _HealthDataWrapper {
8
- }
9
- - (instancetype)initWithEntity:(HealthData *)entity {
10
- self = [super init];
11
- if (self) {
12
- _entity = entity;
13
- self.height = entity.height;
14
- self.timeStamp = entity.timeStamp;
15
- self.weight = entity.weight;
16
- }
17
- return self;
18
- }
19
-
20
- - (void)updateEntity:(HealthData *)entity {
21
- entity.height = self.height;
22
- entity.timeStamp = self.timeStamp;
23
- entity.weight = self.weight;
24
- }
25
- @end
data/out/_PersonWrapper.h DELETED
@@ -1,15 +0,0 @@
1
- #import <Foundation/Foundation.h>
2
-
3
- @class Person;
4
-
5
-
6
- @interface _PersonWrapper : NSObject
7
- @property(nonatomic, strong) NSDate *birthday;
8
- @property(nonatomic, strong) NSString *name;
9
-
10
- @property(readonly, strong, nonatomic) Person *entity;
11
-
12
- - (instancetype)initWithEntity:(Person *)entity;
13
-
14
- - (void)updateEntity:(Person *)entity;
15
- @end
data/out/_PersonWrapper.m DELETED
@@ -1,23 +0,0 @@
1
- #import "_PersonWrapper.h"
2
- #import "Person.h"
3
-
4
- @interface _PersonWrapper ()
5
- @end
6
-
7
- @implementation _PersonWrapper {
8
- }
9
- - (instancetype)initWithEntity:(Person *)entity {
10
- self = [super init];
11
- if (self) {
12
- _entity = entity;
13
- self.birthday = entity.birthday;
14
- self.name = entity.name;
15
- }
16
- return self;
17
- }
18
-
19
- - (void)updateEntity:(Person *)entity {
20
- entity.birthday = self.birthday;
21
- entity.name = self.name;
22
- }
23
- @end
File without changes
File without changes