wara 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/bin/wara +26 -0
- data/coredata/BloodPressureWrapper.h +5 -0
- data/coredata/BloodPressureWrapper.m +15 -0
- data/coredata/CurrentPersonWrapper.h +5 -0
- data/coredata/CurrentPersonWrapper.m +15 -0
- data/coredata/HealthDataWrapper.h +5 -0
- data/coredata/HealthDataWrapper.m +15 -0
- data/coredata/Model.xcdatamodeld/Model.xcdatamodel/contents +43 -0
- data/coredata/NotSameWrapper.h +5 -0
- data/coredata/NotSameWrapper.m +15 -0
- data/coredata/PersonWrapper.h +5 -0
- data/coredata/PersonWrapper.m +15 -0
- data/coredata/_BloodPressureWrapper.h +14 -0
- data/coredata/_BloodPressureWrapper.m +25 -0
- data/coredata/_CurrentPersonWrapper.h +13 -0
- data/coredata/_CurrentPersonWrapper.m +19 -0
- data/coredata/_HealthDataWrapper.h +16 -0
- data/coredata/_HealthDataWrapper.m +25 -0
- data/coredata/_NotSameWrapper.h +24 -0
- data/coredata/_NotSameWrapper.m +41 -0
- data/coredata/_PersonWrapper.h +15 -0
- data/coredata/_PersonWrapper.m +23 -0
- data/lib/wara/version.rb +3 -0
- data/lib/wara.rb +85 -0
- data/out/BloodPressureWrapper.h +5 -0
- data/out/BloodPressureWrapper.m +15 -0
- data/out/CurrentPersonWrapper.h +5 -0
- data/out/CurrentPersonWrapper.m +15 -0
- data/out/HealthDataWrapper.h +5 -0
- data/out/HealthDataWrapper.m +15 -0
- data/out/NotSameWrapper.h +5 -0
- data/out/NotSameWrapper.m +15 -0
- data/out/PersonWrapper.h +5 -0
- data/out/PersonWrapper.m +15 -0
- data/out/_BloodPressureWrapper.h +14 -0
- data/out/_BloodPressureWrapper.m +25 -0
- data/out/_CurrentPersonWrapper.h +13 -0
- data/out/_CurrentPersonWrapper.m +19 -0
- data/out/_HealthDataWrapper.h +16 -0
- data/out/_HealthDataWrapper.m +25 -0
- data/out/_NotSameWrapper.h +24 -0
- data/out/_NotSameWrapper.m +41 -0
- data/out/_PersonWrapper.h +15 -0
- data/out/_PersonWrapper.m +23 -0
- data/spec/spec_helper.rb +78 -0
- data/spec/wara_spec.rb +119 -0
- data/wara.gemspec +27 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5e9f48e6687c5970e7ef4047f95015b861a2d3bf
|
4
|
+
data.tar.gz: 36d75cc8f80a4b74e65853b031ff6c1af456754c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b6b1f5a7656a3ee27604b14343e9da3dfe63be4f2a3a47a6ced379758baa9d591d31c48e3952c0c73c047c2520acd3c5219c3bf736acfb3b651736d673fe34c
|
7
|
+
data.tar.gz: 78fba4b54cae32083ca6c5d6813b9972ee10439d9d436665e69143eefc9dcba76e57056ce93cfbfaa981b74562c3fd63d10d5eb782a36b93e6f80064bd3ea12b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 akuraru
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Wara
|
2
|
+
|
3
|
+
Wara generate a scapegoat for objects of CoreData.
|
4
|
+
|
5
|
+
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.
|
6
|
+
|
7
|
+
Wara is used to generate an object to make changes without the operation of the context if you want to change the entity.
|
8
|
+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'wara'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install wara
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
$ wara -m MyDataModel.xcdatamodeld/MyDataModel.xcdatamodel
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it ( https://github.com/[my-github-username]/wara/fork )
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/wara
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "wara/version"
|
4
|
+
require "wara"
|
5
|
+
require "thor"
|
6
|
+
|
7
|
+
module Wara
|
8
|
+
#= Wara CLI
|
9
|
+
class CLI < Thor
|
10
|
+
default_task :create
|
11
|
+
|
12
|
+
option :model, :type => :string, :aliases => '-m',:required => true, :desc => 'Path to model'
|
13
|
+
option :out, :type => :string, :aliases => '-o', :desc => 'Output directory'
|
14
|
+
desc "create", "create Translation.strings"
|
15
|
+
def create
|
16
|
+
Wara::Core.new.create(options[:model], options[:out])
|
17
|
+
puts 'Generate'
|
18
|
+
end
|
19
|
+
desc "version", "version"
|
20
|
+
def version
|
21
|
+
p Wara::VERSION
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Wara::CLI.start(ARGV)
|
@@ -0,0 +1,43 @@
|
|
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">
|
3
|
+
<entity name="BloodPressure" representedClassName="BloodPressure" parentEntity="HealthData" syncable="YES">
|
4
|
+
<attribute name="bloodPressure" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
|
5
|
+
</entity>
|
6
|
+
<entity name="CurrentPerson" representedClassName="CurrentPerson" syncable="YES">
|
7
|
+
<relationship name="person" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Person" inverseName="currentPeron" inverseEntity="Person" syncable="YES"/>
|
8
|
+
</entity>
|
9
|
+
<entity name="HealthData" representedClassName="HealthData" syncable="YES">
|
10
|
+
<attribute name="height" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
|
11
|
+
<attribute name="timeStamp" optional="YES" attributeType="Date" syncable="YES"/>
|
12
|
+
<attribute name="weight" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
|
13
|
+
<relationship name="person" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Person" inverseName="healthData" inverseEntity="Person" syncable="YES"/>
|
14
|
+
</entity>
|
15
|
+
<entity name="NotHaveCusttomClassName" syncable="YES"/>
|
16
|
+
<entity name="NotSameCusstomClassName" representedClassName="NotSame" isAbstract="YES" syncable="YES">
|
17
|
+
<attribute name="boolean" optional="YES" attributeType="Boolean" syncable="YES"/>
|
18
|
+
<attribute name="data" optional="YES" attributeType="Binary" syncable="YES"/>
|
19
|
+
<attribute name="date" optional="YES" attributeType="Date" syncable="YES"/>
|
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"/>
|
23
|
+
<attribute name="int16" optional="YES" attributeType="Integer 16" defaultValueString="0" syncable="YES"/>
|
24
|
+
<attribute name="int32" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
|
25
|
+
<attribute name="int64" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
|
26
|
+
<attribute name="string" optional="YES" attributeType="String" syncable="YES"/>
|
27
|
+
<attribute name="transformable" optional="YES" attributeType="Transformable" syncable="YES"/>
|
28
|
+
</entity>
|
29
|
+
<entity name="Person" representedClassName="Person" syncable="YES">
|
30
|
+
<attribute name="birthday" optional="YES" attributeType="Date" syncable="YES"/>
|
31
|
+
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
|
32
|
+
<relationship name="currentPeron" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="CurrentPerson" inverseName="person" inverseEntity="CurrentPerson" syncable="YES"/>
|
33
|
+
<relationship name="healthData" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="HealthData" inverseName="person" inverseEntity="HealthData" syncable="YES"/>
|
34
|
+
</entity>
|
35
|
+
<elements>
|
36
|
+
<element name="BloodPressure" positionX="-27" positionY="63" width="128" height="60"/>
|
37
|
+
<element name="CurrentPerson" positionX="-63" positionY="-18" width="128" height="60"/>
|
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
|
+
<element name="NotHaveCusttomClassName" positionX="-54" positionY="36" width="128" height="43"/>
|
41
|
+
<element name="NotSameCusstomClassName" positionX="-45" positionY="45" width="128" height="210"/>
|
42
|
+
</elements>
|
43
|
+
</model>
|
@@ -0,0 +1,14 @@
|
|
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
|
@@ -0,0 +1,25 @@
|
|
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
|
@@ -0,0 +1,13 @@
|
|
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
|
@@ -0,0 +1,19 @@
|
|
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
|
@@ -0,0 +1,16 @@
|
|
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
|
@@ -0,0 +1,25 @@
|
|
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
|
@@ -0,0 +1,24 @@
|
|
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
|
@@ -0,0 +1,41 @@
|
|
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
|
@@ -0,0 +1,15 @@
|
|
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
|
@@ -0,0 +1,23 @@
|
|
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
|
data/lib/wara/version.rb
ADDED
data/lib/wara.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require "wara/version"
|
2
|
+
require 'kconv'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'rexml/document'
|
5
|
+
|
6
|
+
module Wara
|
7
|
+
class Core
|
8
|
+
def create(model, to)
|
9
|
+
to = File.dirname(model) unless to
|
10
|
+
@xml = REXML::Document.new(open(File.expand_path("contents", model)))
|
11
|
+
@objects = @xml.get_elements('model/entity')
|
12
|
+
@entities = @objects.map{ |o|
|
13
|
+
representedClassName = o.attribute("representedClassName")
|
14
|
+
parentEntity = o.attribute("parentEntity")
|
15
|
+
a = o.get_elements("attribute")
|
16
|
+
{
|
17
|
+
"name" => o.attribute("name").value,
|
18
|
+
"representedClassName"=>representedClassName ? representedClassName.value : nil,
|
19
|
+
"parentEntity"=>parentEntity ? parentEntity.value : nil,
|
20
|
+
"attributes"=>a.inject({}) {|s, o|
|
21
|
+
s.merge({ o.attribute("name").value => o.attribute("attributeType").value, })
|
22
|
+
},
|
23
|
+
}
|
24
|
+
}.select{|s| s["representedClassName"]}
|
25
|
+
FileUtils.mkdir_p(to) unless FileTest.exist?(to)
|
26
|
+
@entities.map {|e|
|
27
|
+
file_name = e["representedClassName"]
|
28
|
+
hw = header(e)
|
29
|
+
File.write( File.expand_path("_#{file_name}Wrapper.h", to), hw)
|
30
|
+
mw = implementation(e)
|
31
|
+
File.write( File.expand_path("_#{file_name}Wrapper.m", to), mw)
|
32
|
+
custom_header_name = File.expand_path("#{file_name}Wrapper.h", to)
|
33
|
+
File.write( custom_header_name, custom_header(file_name)) unless FileTest.exist?(custom_header_name)
|
34
|
+
custom_implementation_name = File.expand_path("#{file_name}Wrapper.m", to)
|
35
|
+
File.write( custom_implementation_name, custom_implementation(file_name)) unless FileTest.exist?(custom_implementation_name)
|
36
|
+
}
|
37
|
+
end
|
38
|
+
def header(e)
|
39
|
+
name = e["representedClassName"]
|
40
|
+
entity = e["parentEntity"]
|
41
|
+
import = entity ? "\#import \"#{entity}Wrapper.h\"\n" : "#import <Foundation/Foundation.h>\n"
|
42
|
+
parentEntity = entity ? "#{entity}Wrapper" : "NSObject"
|
43
|
+
getter = entity ? "- (#{name} *)entity;\n" : "@property(readonly, strong, nonatomic) #{name} *entity;\n"
|
44
|
+
"#{import}\n@class #{name};\n\n\n@interface _#{name}Wrapper : #{parentEntity}\n" +
|
45
|
+
e["attributes"].map {|k, v|
|
46
|
+
"@property(nonatomic, strong) #{entityType(v)}#{k};\n"
|
47
|
+
}.inject("") {|s, v| s + v} + "\n#{getter}\n- (instancetype)initWithEntity:(#{name} *)entity;\n\n- (void)updateEntity:(#{name} *)entity;\n@end\n"
|
48
|
+
end
|
49
|
+
def implementation(e)
|
50
|
+
name = e["representedClassName"]
|
51
|
+
init = e["parentEntity"] ? "[super initWithEntity:entity]" : "[super init]"
|
52
|
+
getter = e["parentEntity"] ? "- (BloodPressure *)entity {\n return (BloodPressure *) [super entity];\n}\n\n" : ""
|
53
|
+
first = e["parentEntity"] ? "" : " _entity = entity;\n"
|
54
|
+
update = e["parentEntity"] ? " [super updateEntity:entity];\n" : ""
|
55
|
+
"#import \"_#{name}Wrapper.h\"\n#import \"#{name}.h\"\n\n@interface _#{name}Wrapper ()\n@end\n\n@implementation _#{name}Wrapper {\n}\n#{getter}- (instancetype)initWithEntity:(#{name} *)entity {\n self = #{init};\n if (self) {\n#{first}" +
|
56
|
+
e["attributes"].map {|k, v|
|
57
|
+
" " * 8 + "self.#{k} = entity.#{k};\n"
|
58
|
+
}.inject("") {|s, v| s + v} + " }\n return self;\n}\n\n- (void)updateEntity:(#{name} *)entity {\n#{update}" +
|
59
|
+
e["attributes"].map {|k, v|
|
60
|
+
" " * 4 + "entity.#{k} = self.#{k};\n"
|
61
|
+
}.inject("") {|s, v| s + v} + "}\n@end\n"
|
62
|
+
end
|
63
|
+
def custom_header(file_name)
|
64
|
+
"#import \"_#{file_name}Wrapper.h\"\n\n@interface #{file_name}Wrapper : _#{file_name}Wrapper {}\n// Custom logic goes here.\n@end\n"
|
65
|
+
end
|
66
|
+
def custom_implementation(file_name)
|
67
|
+
"#import \"#{file_name}Wrapper.h\"\n\n\n@interface #{file_name}Wrapper ()\n\n// Private interface goes here.\n\n@end\n\n\n@implementation #{file_name}Wrapper\n\n// Custom logic goes here.\n\n@end\n"
|
68
|
+
end
|
69
|
+
def entityType(value)
|
70
|
+
{
|
71
|
+
"Boolean"=>"NSNumber *",
|
72
|
+
"Binary"=>"NSData *",
|
73
|
+
"Date"=>"NSDate *",
|
74
|
+
"Decimal"=>"NSDecimalNumber *",
|
75
|
+
"Double"=>"NSNumber *",
|
76
|
+
"Float"=>"NSNumber *",
|
77
|
+
"Integer 16"=>"NSNumber *",
|
78
|
+
"Integer 32"=>"NSNumber *",
|
79
|
+
"Integer 64"=>"NSNumber *",
|
80
|
+
"String"=>"NSString *",
|
81
|
+
"Transformable"=>"id ",
|
82
|
+
}[value]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|