diff --git a/.rspec b/.rspec index 83e16f8..e3dd828 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,3 @@ --color --require spec_helper +--format d diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..3513cd3 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,11 @@ +# If you use `rubocop --auto-gen-config, you might want to then uncomment the following line +# inherit_from: .rubocop_todo.yml + +Metrics/ClassLength: + Max: 150 + +Metrics/LineLength: + Max: 120 + +Metrics/BlockLength: + Max: 80 diff --git a/Gemfile b/Gemfile index 06f5d64..c5dc06d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,8 @@ source 'https://rubygems.org' -gem 'nokogiri' +gemspec group :test do gem 'rspec' + gem 'rubocop', '~> 0.47' end diff --git a/Gemfile.lock b/Gemfile.lock index 692a6c4..b410013 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,30 +1,56 @@ +PATH + remote: . + specs: + gyro (1.0.0) + liquid (~> 3.0) + nokogiri (~> 1.6.8) + GEM remote: https://rubygems.org/ specs: - diff-lcs (1.2.5) - mini_portile (0.6.2) - nokogiri (1.6.6.2) - mini_portile (~> 0.6.0) - rspec (3.3.0) - rspec-core (~> 3.3.0) - rspec-expectations (~> 3.3.0) - rspec-mocks (~> 3.3.0) - rspec-core (3.3.2) - rspec-support (~> 3.3.0) - rspec-expectations (3.3.1) + ast (2.3.0) + diff-lcs (1.3) + liquid (3.0.6) + mini_portile2 (2.1.0) + nokogiri (1.6.8.1) + mini_portile2 (~> 2.1.0) + parallel (1.11.2) + parser (2.4.0.0) + ast (~> 2.2) + powerpack (0.1.1) + rainbow (2.2.2) + rake + rake (12.0.0) + rspec (3.6.0) + rspec-core (~> 3.6.0) + rspec-expectations (~> 3.6.0) + rspec-mocks (~> 3.6.0) + rspec-core (3.6.0) + rspec-support (~> 3.6.0) + rspec-expectations (3.6.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-mocks (3.3.2) + rspec-support (~> 3.6.0) + rspec-mocks (3.6.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-support (3.3.0) + rspec-support (~> 3.6.0) + rspec-support (3.6.0) + rubocop (0.49.1) + parallel (~> 1.10) + parser (>= 2.3.3.1, < 3.0) + powerpack (~> 0.1) + rainbow (>= 1.99.1, < 3.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-progressbar (1.8.1) + unicode-display_width (1.2.1) PLATFORMS ruby DEPENDENCIES - nokogiri + gyro! rspec + rubocop (~> 0.47) BUNDLED WITH - 1.14.5 + 1.13.7 diff --git a/README.md b/README.md index 4ce7f1e..65826e5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ + # Gyro -Gyro is a tool to generate [Realm](https://realm.io) model classes, for both Android (Java) and iOS/macOS (ObjC & Swift), from an `.xcdatamodel` file. +[![gem version](https://img.shields.io/gem/v/gyro.svg?style=flat-square)](https://rubygems.org/gems/gyro) +[![build circle ci](https://img.shields.io/circleci/project/github/NijiDigital/gyro.svg?style=flat-square)](https://circleci.com/gh/NijiDigital/gyro) +[![Twitter](https://img.shields.io/badge/twitter-@Niji_Digital-blue.svg?style=flat-square)](http://twitter.com/Niji_Digital) + +Gyro is a tool to generate [Realm](https://realm.io) model classes, for both Android (Java) and iOS/macOS (Swift), from an `.xcdatamodel` file. ---
@@ -25,14 +30,6 @@ This will allow you to design your model in a visual way (rather than by code), The `.xcdatamodel` file is the input of the script. - -## License - -This tool is under [the Apache 2 License](LICENSE). - -It has been initially developed by [Niji](http://www.niji.fr) and is in no way affiliated to the [Realm](https://realm.io) company. - - ## Installation Gyro is on RubyGems, so this means you can simply install it by using this command in your terminal: @@ -41,37 +38,33 @@ Gyro is on RubyGems, so this means you can simply install it by using this comma gem install gyro ``` -Then invoke it with the appropriate options (see next paragraph), like this: +_Alternativly, you could also clone this repository anywhere you want on your machine, then build and install the local gem_ ```bash -gyro -m --ios ~/Dev/MyProject/RealmModel --swift +gem build gyro.gemspec +gem install gyro-1.0.0.gem ``` -_Alternativly, you could also simply clone this repository anywhere you want on your machine, then run the `bin/gyro` executable directly from where you cloned it_ +## Usage +Invoke it with the appropriate options like this: -## Command line arguments - -Gyro is a command line tool. The available parameters are as follows. You can also use `-h` do display the usage and available parameters/flags in the Terminal of course. +```bash +gyro --model --template --output --param : +``` +`` is the path to the xcdatamodel file -| Short flag | Long flag | Description | Android | iOS | -| ---------- | --------- | ----------- |:-------:|:---:| -| `-m` | `--model` | Path to the  `.xcdatamodel` file. If this parameter is not given, Gyro will look for a `.xcdatamodel` | ✅ | ✅ | -| `-a` | `--android` | Path to the directory where the generated files for Android will be created (e.g.: home/documents/dev/android/realm_project/com/niji/data) | ✅ | ➖ | -| `-p` | `--package` | Full name of the Android "data" package (e.g.: com.niji.data) | ✅ | ➖ | -| `-i` | `--ios` | Path to the directory where the generated files for iOS/macOS will be created | ➖ | ✅ | -| `-j` | `--json` | Create the Realm-JSON categories (https://github.com/matthewcheok/Realm-JSON) | ➖ | ☑️ | -| `-f` | `--framework` | Tells whether the project uses CocoaPods Frameworks | ➖ | ☑️ | -| `-s` | `--swift` | Use Swift for the iOS/macOS generation | ➖ | ☑️ | -| `-n` | `--nsnumber` | Generate `NSNumber`s instead of Int/BOOL/Float types | ➖ | ☑️ | -| `-w` | `--wrappers` | Use type wrappers for Java (Integer, Double, …) for optional attributes instead of primitive types (int, double, …) | ☑️ | ➖ | -| `-x` | `--annotations` | Annotate the getters/setters of the generated classes with `@Nullable` for any optional attribute/relationship, and with `@NonNull` for any non-optional attribute/relationship | ☑️ | ➖ | -| `-h` | `--help` | Show help | ☑️ | ☑️ | -| `-v` | `--version` | Show the current version number of Gyro | ☑️ | ☑️ | +`` is the path to the output directory file -_Caption: ✅ Mandatory flag for this platform / ☑️ Optional flag usable for this platform / ➖ Not applicable for this platform_ +`` is the name of the template. Below you have the list of templates. +If you want additional information about templates you can go to the documentation for each : +- [android](lib/templates/android/README.md) +- [swift3](lib/templates/swift3/README.md) +- [decodable](lib/templates/decodable/README.md) +- [swift3-variant](lib/templates/swift3-variant/README.md) +- [object-mapper](lib/templates/object-mapper/README.md) ## Annotating your `xcdatamodel` @@ -79,776 +72,14 @@ The `.xcdatamodel` Xcode editor allows you to add "user infos" to your entities, _To define a User Info key in Xcode's xcdatamodel editor, select the entity or attribute you want to add a User Info to, then select the 3rd tab in the inspector on the right ("Data Model Inspector", or Cmd-Alt-3), and fill the information you want in the "User Info" section there._ -With the help of these "user infos", you will be able to give Gyro extra information about your model classes. For example, you can tell which attribute is the primary key, the attributes to ignore, the JSON mappings, … - -Below are details about how to annotate your `.xcdatamodel` entities and attributes to be able to leverage each Realm features when generating your Realm models with Gyro. - - ---- - - -### Primary key - -To tell which attribute will be used as a primary key, add the following 'user info' to **the entity**: - -| Key | Value | -|-----|-------| -| `identityAttribute` | `name_of_the_attribute` | - - -__Example__: On the "FidelityCard" entity: - -![Primary Key](documentation/primary_key.png) - - -
-📑 Sample of the generated code in Java (Android) - -```java -package com.niji.data; - -import io.realm.RealmObject; -import io.realm.annotations.PrimaryKey; - -/* DO NOT EDIT | Generated by gyro */ - -public class FidelityCard extends RealmObject { - - @PrimaryKey - private short identifier; - private int points; - private User user; - [...] -} -``` -
- -
-📑 Sample of the generated code in Objective-C (iOS) - -```objc -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMFidelityCard.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMFidelityCard - -#pragma mark - Superclass Overrides - -+ (NSString *)primaryKey -{ - return @"identifier"; -} - -@end -``` -
- - ---- - - -### Ignore attribute - -You can decide to ignore some attributes of the `.xcdatamodel` file. They will not be persisted to Realm. To do so, add the following 'user info' to **the attribute**: - -| Key | Value | -|-----|-------| -| `realmIgnored` | `value` | - - -__Example__: on the attribute `ignored` of the entity `Shop`: - -![Ignored Attribute](documentation/ignored.png) - - -
-📑 Sample of the generated code in Java (Android) - -```java -package com.niji.data; - -import io.realm.RealmList; -import io.realm.RealmObject; -import io.realm.annotations.Ignore; - -/* DO NOT EDIT | Generated by gyro */ - -public class Shop extends RealmObject { - - private String name; - private String readOnly; - private RealmList products; - @Ignore - private String ignored; - [...] -} -``` -
- -
-📑 Sample of the generated code in Objective-C (iOS) - -```objc -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop - -#pragma mark - Superclass Overrides - -// Specify properties to ignore (Realm won't persist these) -+ (NSArray *)ignoredProperties -{ - return @[@"ignored"]; -} -@end -``` -
- - ---- - - -### Read only - -On iOS/macOS, you can define attributes which are not persisted and whose value is computed dynamically. -To do so, add the following 'user info' to **the attribute** - -| Key | Value | -|-----|-------| -| `realmReadOnly` | `the_code_source_to_generate` | - - -__Example__: On the `readOnly` attribute of the `Shop` entity: - -![Read Only](documentation/read_only.png) - - -
-📑 Sample of the generated code in Objective-C (iOS) - -```objc -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop - -#pragma mark - Superclass Overrides - -- (NSString *)readOnly -{ - return self.name; -} - -@end -``` -
- - ---- - - -### Inverse Relationships - -In realm, when you have both A -> B and B -> A relationships, you have to choose one of those relationships to be the primary one (e.g. A -> B) — that will be stored in Realm — and the other inverse relationship will then be **computed** by code. [For more information, see the related RealmSwift documentation on Inverse Relationships](https://realm.io/docs/swift/latest/#inverse-relationships). - -To mark a relationship as being an inverse relationship (the B -> A relationship and not the primary A -> B one), the convention in `gyro` is to **suffix the name of the relationship with an underscore `_`** . - -This will then generate the following code in Swift for that inverse relationship: - -```swift -LinkingObjects(fromType: A.self, property: "b")` -``` - -If your inverse relationship is defined to point to a unique object (inverse of a `1-*` relationship for exemple, and not a `*-*` one), the generated code will contain both the plural form of the computed variable and a singular form returning its first element, for convenience: - -```swift -let owners = LinkingObjects(fromType: Person.self, property: "dogs")` -var owner: Person? { return owners.first } -``` - - ---- - - -### Optionnals fields and wrapper types - -On Android, the `-w`/`--wrappers` flag allows you to use wrapper types (`Double`, `Short`, …) for optional fields instead of primitive types (`double`, `short`, …). - -
-📑 Sample of the generated code in Java (Android) - -```java -package com.niji.data; - -import io.realm.RealmObject; -import io.realm.annotations.PrimaryKey; - -/* DO NOT EDIT | Generated by gyro */ - -public class FidelityCard extends RealmObject { - - @PrimaryKey - private short identifier; // "optional" checkbox not checked in the xcdatamodel - private Integer points; // "optional" checkbox checked in the xcdatamodel - private User user; - [...] -} -``` -
- - ---- - - -### Support Annotations - -On Android, the flag `-x`/`--annotations` allows you to annotate class attributes' getters & setters with `@Nullable` (if the attribute is optional) or `@NonNull` (if it isn't) attributes. -This option can be combined with the `-w` wrapper flag to generate a safer and more secure code in Android Studio, generating proper warnings if misused. - -
-📑 Sample of the generated code in Java (Android) - -```java -package com.niji.data; - -import io.realm.RealmObject; -import io.realm.annotations.PrimaryKey; - -/* DO NOT EDIT | Generated by gyro */ - -public class FidelityCard extends RealmObject { - - @PrimaryKey - private short identifier; // "optional" checkbox not checked in the xcdatamodel - private Integer points; // "optional" checkbox checked in the xcdatamodel - private User user; - [...] - - @android.support.annotation.Nullable - public Integer getPoints() { - return points; - } - - public void setPoints(@android.support.annotation.Nullable final Integer points) { - this.points = points; - } - -} -``` -
- -Furthermore, it's possible to add custom annotations to your fields. -To do that, simply add the key/value pair to the UserInfos of the attribute to annotate: - -| Key | Value | -|-----|-------| -| `supportAnnotation` | `AnnotationToAdd` | - - -__Example__: If you wish to add the `IntRange(from=0,to=255)` annotation to an attribute, use the following: - -![Support Annotation](documentation/support_annotation.png) - - -
-📑 Sample of the generated code in Java (Android) - -```java -package com.gyro.tests; - -import io.realm.RealmObject; - -/* DO NOT EDIT | Generated by gyro */ - -public class FidelityCard extends RealmObject { - - public interface Attributes { - String IDENTIFIER = "identifier"; - String POINTS = "points"; - } - - private short identifier; - @android.support.annotation.IntRange(from=0,to=255) - private int points; - - public short getIdentifier() { - return identifier; - } - - public void setIdentifier(final short identifier) { - this.identifier = identifier; - } - - @android.support.annotation.IntRange(from=0,to=255) - public int getPoints() { - return points; - } - - public void setPoints(@android.support.annotation.IntRange(from=0,to=255) final int points) { - this.points = points; - } -} -``` -
- - ---- - - -### Handling enums - -Sometimes, an `Int` attribute in the model actually represents an `enum` member in your model. To deal with this case, you can add the following two key/value pairs to this **attribute**: - -| Key | Value | -|-----|-------| -| `enumType` | `my_type` | -| `enumValues` | `my_value_1, my_value_2, my_value_3` | - -> _Note: If you also add the `JSONKeyPath` User Info key to your attribute in addition to enums, you'll have to add the `JSONValues` to also tell the mapping between the `enumValues` and the matching possible values found in the JSON. See the [JSON Mapping](#json-mapping) below for more details._ - -__Example__: On the attribute `type` of the `Shop` entity. - -![enum](documentation/enum.png) - - -
-📑 Sample of the generated code in Java (Android) - -`Shop.java`: - -```java -package com.niji.data; - -import io.realm.RealmObject; - -/* DO NOT EDIT | Generated by gyro */ - -public class Shop extends RealmObject { - private String name; - private Type type; - [...] -} -``` - -`Type.java`: - -```java -package com.niji.data; - -/* DO NOT EDIT | Generated by gyro */ - -public enum Type { - TYPE_ONE, - TYPE_TWO, - TYPE_THREE -} -``` -
- -
-📑 Sample of the generated code in Objective-C (iOS) - -`RLMShop.h`: - -```objc -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMTypes.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop : RLMObject - -#pragma mark - Properties - -@property NSString *name; -@property RLMType type; - -@end -``` - -`RLMTypes.h`: - -```objc -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Types - -typedef NS_ENUM(int, RLMType) { - RLMTypeOne = 0, - RLMTypeTwo, - RLMTypeThree -}; -``` -
- -
-📑 Sample of the generated code in Swift (iOS) - -`Shop.swift`: - -```swift -/* DO NOT EDIT | Generated by gyro */ - -import RealmSwift - -final class Shop: Object { - - enum Attributes: String { - case Name = "name" - case OptionalValue = "optionalValue" - case Type = "type" - } - - dynamic var name: String = "" - dynamic var optionalValue: String? = nil - var optionalValueEnum: OptValue? { - get { - guard let optionalValue = optionalValue, - let enumValue = OptValue(rawValue: optionalValue) - else { return nil } - return enumValue - } - set { optionalValue = newValue?.rawValue ?? nil } - } - - dynamic var type: String = "" - var typeEnum: Type? { - get { - guard let enumValue = Type(rawValue: type) else { return nil } - return enumValue - } - set { type = newValue?.rawValue ?? "" } - } -} -``` - -`Type.swift`: - -```swift -/* DO NOT EDIT | Generated by gyro */ - -enum Type: String { - case TypeOne = "type_one" - case TypeTwo = "type_two" - case TypeThree = "type_three" -} -``` - -`OptValue.swift` - -```swift -/* DO NOT EDIT | Generated by gyro */ - -enum OptValue: String { - case OptValueOne = "opt_value_one" - case OptValueTwo = "opt_value_two" - case OptValueThree = "opt_value_three" -} -``` -
- -> **Note**: For Android and Swift, each enum is created in a separate file. For ObjC, all the enums are created in the file RLMTypes.h - - ---- - - -### Add comments to the generated classes - -To make the generated code more readable, it's possible to add comments on an entity — e.g. to provide a short description of what this entity is supposed to represent. - -To do so, simply add the following key/value pair to your **entity** in your `.xcdatamodel`: - -| Key | Value | -|-----|-------| -| `comment` | `the_comment_text_here` | - -A code commend (`/** … */`) will then be generated (in the `.h` (ObjC), `.swift` (Swift) or `.java` (Android)) just before the class declaration, e.g. to help the developer understand what this class is for. - - ---- - - -### JSON Mapping - -You can also add the json mapping for each **attribute** or **relationship** with the following key/value pair: - -| Key | Value | -|-----|-------| -| `JSONKeyPath` | `json_field_name` | - -This key is only used when using the `--json` flag. - -Currently, this will then generate: - - * Code for `ObjectMapper` on iOS (in the future we plan to generate `Sourcery` annotations instead so that people can choose whatever JSON library they prefer). - * `GSON` annotations (`@SerializedName(…)`) for Android - -__Example__: On the 'name' attribute of the 'Shop' entity: - -![JSONKeyPath](documentation/json.png) - - -
-📑 Sample of the generated code in Java (Android) - -Sur Android, nous utilisons la librairie GSON - -```java -package com.niji.data; - -import com.google.gson.annotations.SerializedName; - -import io.realm.RealmList; -import io.realm.RealmObject; - -/* DO NOT EDIT | Generated by gyro */ - -public class Shop extends RealmObject { - - @SerializedName("json_name") - private String name; - private RealmList products; - [...] -} -``` -
- -
-📑 Sample of the generated code in Objective-C (iOS) - -On iOS, we use the Realm-JSON library and generate them in `MyEntity+JSON.m` category files. - -`RLMShop+JSON.m`: - -```objc -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop+JSON.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop (JSON) - -+ (NSDictionary *)JSONInboundMappingDictionary -{ - return @{ - @"json_name" : @"name" - }; -} - -+ (NSDictionary *)JSONOutboundMappingDictionary -{ - return @{ - @"name" : @"json_name" - }; -} - -@end -``` -
- -#### Combine JSONKeyPath and enums - -Note that you can **combine that `JSONKeyPath` key with enums** (see [Handling enums](#handling-enums) above). If you declared the User Info keys to make your attribute an enum (`enumType` + `enumValues`) in addition to `JSONKeyPath`, you'll have to also add the `JSONValues` key to list the corresponding values in the JSON for those `enumValues`. - -| Key | Value | -|-----|-------| -| `JSONValues` | `valeur_json_1,valeur_json_2,valeur_json_3` | - -The number of items listed for that `JSONValues` key must be the same as the number of items listed for the `enumValues` keys, obviously. - -__Example__: - ![enum_json](documentation/enum_json.png) +With the help of these "user infos", you will be able to give Gyro extra information about your model classes. For example, you can tell which attribute is the primary key, the attributes to ignore, the JSON mappings, … -
-📑 Sample of the generated code in Java (Android) - -```java -package com.niji.data; - -import com.google.gson.annotations.SerializedName; - -/* DO NOT EDIT | Generated by gyro */ - -public enum Type { - - @SerializedName("json_type_one")TYPE_ONE, - @SerializedName("json_type_two")TYPE_TWO, - @SerializedName("json_type_three")TYPE_THREE -} -``` -
- -
-📑 Sample of the generated code in Objective-C (iOS) - -`RLMShop+JSON.m`: - -```objc -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop+JSON.h" -#import "RLMTypes.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop (JSON) - -+ (NSValueTransformer *)typeJSONTransformer -{ - return [MCJSONValueTransformer valueTransformerWithMappingDictionary:@{ - @"json_type_one" : @(RLMTypeOne), - @"json_type_two" : @(RLMTypeTwo), - @"json_type_three" : @(RLMTypeThree) - }]; -} - -@end -``` -
- - ---- - - -### Custom ValueTransformers - -Only available on iOS (as Android uses the GSON library), custom `ValueTransformers` allows you to e.g. convrt a `String` into an `Int` or a `Date` when parsing the JSON. They are only used when using the `--json` flag. - -To create a specific `ValueTransformer` for a field: - -* Create your `ValueTransformer` custom class inheriting `NSValueTransformer` and add it to your project -* Select the attribute that will need this transformer, and in the UserInfo field, add a pair for the **transformer** key whose value should be the name of the `ValueTransformer` class to use: - -| Key | Value | -|-----|-------| -| `transformer` | `NameOfTheTransformerClass` | - -__Example__: - -![transformer](documentation/transformer.png) - - -
-📑 Sample of the generated code in Objective-C (iOS) - -`gyro` will produce the following code. (In this example, attributes `attrDouble` and `attrInteger32` don't have a **transformer** key set in their UserInfo). - -```objc -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop+JSON.h" -#import "MPDecimalTransformer.h" -#import "MPIntegerTransformer.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop (JSON) - -+ (NSDictionary *)JSONInboundMappingDictionary -{ - return @{ - @"attrDecimal" : @"attrDecimal", - @"attrDouble" : @"attrDouble", - @"attrFloat" : @"attrFloat", - @"attrInteger16" : @"attrInteger16", - @"attrInteger32" : @"attrInteger32", - @"attrInteger64" : @"attrInteger64" - }; -} - -+ (NSDictionary *)JSONOutboundMappingDictionary -{ - return @{ - @"attrDecimal" : @"attrDecimal", - @"attrDouble" : @"attrDouble", - @"attrFloat" : @"attrFloat", - @"attrInteger16" : @"attrInteger16", - @"attrInteger32" : @"attrInteger32", - @"attrInteger64" : @"attrInteger64" - }; -} - -+ (NSValueTransformer *)attrDecimalJSONTransformer -{ - return [[MPDecimalTransformer alloc] init]; -} - -+ (NSValueTransformer *)attrFloatJSONTransformer -{ - return [[MPDecimalTransformer alloc] init]; -} - -+ (NSValueTransformer *)attrInteger16JSONTransformer -{ - return [[MPIntegerTransformer alloc] init]; -} +**For more information about "user infos", you can see the dedicated documentation [here](USER-INFO.md).** -+ (NSValueTransformer *)attrInteger64JSONTransformer -{ - return [[MPIntegerTransformer alloc] init]; -} +## License -@end +This tool is under [the Apache 2 License](LICENSE). -``` -
+It has been initially developed by [Niji](http://www.niji.fr) and is in no way affiliated to the [Realm](https://realm.io) company. diff --git a/USER-INFO.md b/USER-INFO.md new file mode 100644 index 0000000..4d7c1f9 --- /dev/null +++ b/USER-INFO.md @@ -0,0 +1,703 @@ + +# User info keys documentation + +Below are details about how to annotate your `.xcdatamodel` entities and attributes to be able to leverage each Realm features when generating your Realm models with Gyro. + +--- + +### Summary : + +- [Primary key](#primary-key) +- [Ignore attribute](#ignore-attribute) +- [Read only](#read-only) +- [Inverse Relationships](#inverse-relationships) +- [Optionnals fields and wrapper types](#optionnals-fields-and-wrapper-types) +- [Support Annotations](#support-annotations) +- [Handling enums](#handling-enums) +- [Add comments to the generated classes](#add-comments-to-the-generated-classes) +- [JSON Mapping](#json-mapping) + - [Combine JSONKeyPath and enums](#combine-jsonkeypath-and-enums) +- [Custom ValueTransformers](#custom-valuetransformers) + +--- + + +# Primary key + +To tell which attribute will be used as a primary key, add the following 'user info' to **the entity**: + +| Key | Value | +|-----|-------| +| `identityAttribute` | `name_of_the_attribute` | + + +__Example__: On the "FidelityCard" entity: + +![Primary Key](documentation/primary_key.png) + + +
+📑 Sample of the generated code in Java (Android) + +```java +package com.gyro.tests; + +import io.realm.RealmObject; +import io.realm.annotations.PrimaryKey; + +/* DO NOT EDIT | Generated by gyro */ + +public class FidelityCard extends RealmObject { + + [...] + @PrimaryKey + private short identifier; + [...] +} +``` +
+ +
+📑 Sample of the generated code in Swift (iOS) + +```swift +/* DO NOT EDIT | Generated by gyro */ + +import RealmSwift + +final class FidelityCard: Object { + + [...] + dynamic var identifier: Int16 = 0 + + override static func primaryKey() -> String? { + return "identifier" + } + +} +``` +
+ + +--- + + +# Ignore attribute + +You can decide to ignore some attributes of the `.xcdatamodel` file. They will not be persisted to Realm. To do so, add the following 'user info' to **the attribute**: + +| Key | Value | +|-----|-------| +| `realmIgnored` | `value` | + + +__Example__: on the attribute `ignored` of the entity `Shop`: + +![Ignored Attribute](documentation/ignored.png) + + +
+📑 Sample of the generated code in Java (Android) + +```java +package com.gyro.tests; + +import io.realm.RealmList; +import io.realm.RealmObject; +import io.realm.annotations.Ignore; + +/* DO NOT EDIT | Generated by gyro */ + +public class Shop extends RealmObject { + + [...] + @Ignore + private String ignored; + [...] +} +``` +
+ +
+📑 Sample of the generated code in Swift (iOS) + +```swift +/* DO NOT EDIT | Generated by gyro */ + +import RealmSwift + +final class Shop: Object { + + dynamic var ignored: String = "" + + // Specify properties to ignore (Realm won't persist these) + override static func ignoredProperties() -> [String] { + return ["ignored"] + } + +} + +``` +
+ + +--- + + +# Read only (DEPRECATED) + +
+ Information about read only 'user info' +On iOS/macOS, you can define attributes which are not persisted and whose value is computed dynamically. +To do so, add the following 'user info' to **the attribute** + +| Key | Value | +|-----|-------| +| `realmReadOnly` | `the_code_source_to_generate` | + + +__Example__: On the `readOnly` attribute of the `Shop` entity: + +![Read Only](documentation/read_only.png) +
+ +
+📑 Sample of the generated code in Objective-C (iOS) + +```objc +// DO NOT EDIT | Generated by gyro + +//////////////////////////////////////////////////////////////////////////////// + +#pragma mark - Imports + +#import "RLMShop.h" + +//////////////////////////////////////////////////////////////////////////////// + +#pragma mark - Implementation + +@implementation RLMShop + +#pragma mark - Superclass Overrides + +- (NSString *)readOnly +{ + return self.name; +} + +@end +``` +
+ + +--- + + +# Inverse Relationships + +In realm, when you have both A -> B and B -> A relationships, you have to choose one of those relationships to be the primary one (e.g. A -> B) — that will be stored in Realm — and the other inverse relationship will then be **computed** by code. [For more information, see the related RealmSwift documentation on Inverse Relationships](https://realm.io/docs/swift/latest/#inverse-relationships). + +To mark a relationship as being an inverse relationship (the B -> A relationship and not the primary A -> B one), the convention in `gyro` is to **suffix the name of the relationship with an underscore `_`** . + +This will then generate the following code in Swift for that inverse relationship: + +```swift +LinkingObjects(fromType: A.self, property: "b")` +``` + +If your inverse relationship is defined to point to a unique object (inverse of a `1-*` relationship for exemple, and not a `*-*` one), the generated code will contain both the plural form of the computed variable and a singular form returning its first element, for convenience: + +```swift +let owners = LinkingObjects(fromType: Person.self, property: "dogs") +var owner: Person? { return owners.first } +``` + + +--- + + +# Optionnals fields and wrapper types + +On Android, the `-p use_wrappers` flag allows you to use wrapper types (`Double`, `Short`, …) for optional fields instead of primitive types (`double`, `short`, …). + +
+📑 Sample of the generated code in Java (Android) + +```java +package com.gyro.tests; + +import io.realm.RealmObject; + +/* DO NOT EDIT | Generated by gyro */ + +public class FidelityCard extends RealmObject { + + @PrimaryKey + private short identifier; // "optional" checkbox not checked in the xcdatamodel + private Integer points; // "optional" checkbox checked in the xcdatamodel + +} + +``` +
+ +--- + + +# Support Annotations + +On Android, the flag `-p support_annotations` allows you to annotate class attributes' getters & setters with `@Nullable` (if the attribute is optional) or `@NonNull` (if it isn't) attributes. +This option can be combined with the `-p use_wrappers` wrapper flag to generate a safer and more secure code in Android Studio, generating proper warnings if misused. + +
+📑 Sample of the generated code in Java (Android) + +```java +package com.gyro.tests; + +import io.realm.RealmObject; + +/* DO NOT EDIT | Generated by gyro */ + +public class FidelityCard extends RealmObject { + + private short identifier; + @android.support.annotation.IntRange(from=0,to=255) + private Integer points; + private User user; + + [...] + + @android.support.annotation.Nullable + @android.support.annotation.IntRange(from=0,to=255) + public Integer getPoints() { + return points; + } + + public void setPoints(@android.support.annotation.Nullable @android.support.annotation.IntRange(from=0,to=255) final Integer points) { + this.points = points; + } + [...] +} + +``` +
+ +Furthermore, it's possible to add custom annotations to your fields. +To do that, simply add the key/value pair to the UserInfos of the attribute to annotate: + +| Key | Value | +|-----|-------| +| `supportAnnotation` | `AnnotationToAdd` | + + +__Example__: If you wish to add the `IntRange(from=0,to=255)` annotation to an attribute, use the following: + +![Support Annotation](documentation/support_annotation.png) + + +
+📑 Sample of the generated code in Java (Android) + +```java +package com.gyro.tests; + +import io.realm.RealmObject; + +/* DO NOT EDIT | Generated by gyro */ + +public class FidelityCard extends RealmObject { + + public interface Attributes { + String IDENTIFIER = "identifier"; + String POINTS = "points"; + } + + private short identifier; + @android.support.annotation.IntRange(from=0,to=255) + private int points; + + public short getIdentifier() { + return identifier; + } + + public void setIdentifier(final short identifier) { + this.identifier = identifier; + } + + @android.support.annotation.IntRange(from=0,to=255) + public int getPoints() { + return points; + } + + public void setPoints(@android.support.annotation.IntRange(from=0,to=255) final int points) { + this.points = points; + } +} +``` +
+ + +--- + + +# Handling enums + +Sometimes, an `Int` attribute in the model actually represents an `enum` member in your model. To deal with this case, you can add the following two key/value pairs to this **attribute**: + +| Key | Value | +|-----|-------| +| `enumType` | `my_type` | +| `enumValues` | `my_value_1, my_value_2, my_value_3` | + +> _Note: If you also add the `JSONKeyPath` User Info key to your attribute in addition to enums, you'll have to add the `JSONValues` to also tell the mapping between the `enumValues` and the matching possible values found in the JSON. See the [JSON Mapping](#json-mapping) below for more details._ + +__Example__: On the attribute `type` of the `Shop` entity. + +![enum](documentation/enum.png) + + +
+📑 Sample of the generated code in Java (Android) + +`Shop.java`: + +```java +package com.gyro.tests; + +/* DO NOT EDIT | Generated by gyro */ + +import io.realm.RealmObject; + +public class Shop extends RealmObject { + private String name; + private String type; + + public String getType() { + return type; + } + + public Type getTypeEnum() { + return Type.get(getType()); + } + + public void setTypeEnum(final Type type) { + this.type = type.getJsonValue(); + } + [...] +} + + +``` + +`Type.java`: + +```java +package com.gyro.tests; + +/* DO NOT EDIT | Generated by gyro */ + +public enum Type { + + TYPE_ONE("TypeOne"), + TYPE_TWO("TypeTwo"), + TYPE_THREE("TypeThree"); + [...] +} +``` +
+ +
+📑 Sample of the generated code in Swift (iOS) + +`Shop.swift`: + +```swift +/* DO NOT EDIT | Generated by gyro */ + +import RealmSwift + +final class Shop: Object { + [...] + dynamic var type: String = "" + var typeEnum: Type? { + get { + guard let enumValue = Type(rawValue: type) else { return nil } + return enumValue + } + set { type = newValue?.rawValue ?? "" } + } +} +``` + +`Type.swift`: + +```swift +/* DO NOT EDIT | Generated by gyro */ + +enum Type: String { + case typeOne = "TypeOne" + case typeTwo = "TypeTwo" + case typeThree = "TypeThree" +} + +``` +
+ +> **Note**: For Android and Swift, each enum is created in a separate file. + +--- + + +# Add comments to the generated classes + +To make the generated code more readable, it's possible to add comments on an entity — e.g. to provide a short description of what this entity is supposed to represent. + +To do so, simply add the following key/value pair to your **entity** in your `.xcdatamodel`: + +| Key | Value | +|-----|-------| +| `comment` | `the_comment_text_here` | + +A code commend (`/** … */`) will then be generated (`.swift` (Swift) or `.java` (Android)) just before the class declaration, e.g. to help the developer understand what this class is for. + + +--- + + +# JSON Mapping + +You can also add the json mapping for each **attribute** or **relationship** with the following key/value pair: + +| Key | Value | +|-----|-------| +| `JSONKeyPath` | `json_field_name` | + +This key is only used when using the `ObjectMapper` or `Decodable` template. + +Currently, this will then generate: + + * Code for `ObjectMapper` or `Decodable` on iOS (in the future we plan to generate `Sourcery` annotations instead so that people can choose whatever JSON library they prefer). + * `GSON` annotations (`@SerializedName(…)`) for Android + +__Example__: On the 'name' attribute of the 'Shop' entity: + +![JSONKeyPath](documentation/json.png) + + +
+📑 Sample of the generated code in Java (Android) + +Sur Android, nous utilisons la librairie GSON + +```java +package com.gyro.tests; + +/* DO NOT EDIT | Generated by gyro */ + +import com.google.gson.annotations.SerializedName; + +import io.realm.RealmList; +import io.realm.RealmObject; + +public class Shop extends RealmObject { + + @SerializedName("json_name") + private String name; + private RealmList products; + [...] +} +``` +
+ +
+📑 Sample of the generated code in Swift (iOS) + +On iOS, we support `Decodable` and `Object Mapper` templates for parsing/mapping. + +`Shop+Decodable.swift`: + +```swift +/* DO NOT EDIT | Generated by gyro */ + +import protocol Decodable.Decodable +import Decodable + +extension Shop: Decodable { + + static func decode(_ json: Any) throws -> Shop { + let shop = Shop() + shop.name = try json => "name" + let productsSandbox: [Product] = try json => "products" + shop.products.append(objectsIn: productsSandbox) + return shop + } +} + +``` + +`ShopMapper.swift`: + +```swift +/* DO NOT EDIT | Generated by gyro */ + +import ObjectMapper + +extension Shop: Mappable { + + // MARK: Initializers + + convenience init?(map: Map) { + self.init() + } + + // MARK: Mappable + + func mapping(map: Map) { + + // MARK: Attributes + self.name <- map["name"] + + // MARK: Relationships + self.products <- (map["products"], ListTransform()) + } +} +``` + +
+ + +## Combine JSONKeyPath and enums + +Note that you can **combine that `JSONKeyPath` key with enums** (see [Handling enums](#handling-enums) above). If you declared the User Info keys to make your attribute an enum (`enumType` + `enumValues`) in addition to `JSONKeyPath`, you'll have to also add the `JSONValues` key to list the corresponding values in the JSON for those `enumValues`. + +| Key | Value | +|-----|-------| +| `JSONValues` | `valeur_json_1,valeur_json_2,valeur_json_3` | + +The number of items listed for that `JSONValues` key must be the same as the number of items listed for the `enumValues` keys, obviously. + +__Example__: + +![enum_json](documentation/enum_json.png) + + +
+📑 Sample of the generated code in Java (Android) + +`Type.java`: + +```java +package com.gyro.tests; + +/* DO NOT EDIT | Generated by gyro */ + +public enum Type { + + TYPE_ONE("json_type_one"), + TYPE_TWO("json_type_two"), + TYPE_THREE("json_type_three"); + [...] +} +``` +
+ +
+📑 Sample of the generated code in Swift (iOS) + +`Type.swift`: + +```swift +/* DO NOT EDIT | Generated by gyro */ + +enum Type: String { + case typeOne = "json_type_one" + case typeTwo = "json_type_two" + case typeThree = "json_type_three" +} + +``` +
+ + +--- + + +# Custom ValueTransformers + +Only available on iOS (as Android uses the GSON library), custom `ValueTransformers` allows you to e.g. convrt a `String` into an `Int` or a `Date` when parsing the JSON. They are only used when using `ObjectMapper` or `Decodable` template. + +To create a specific `ValueTransformer` for a field: + +* Create your `ValueTransformer` custom class inheriting `NSValueTransformer` and add it to your project +* Select the attribute that will need this transformer, and in the UserInfo field, add a pair for the **transformer** key whose value should be the name of the `ValueTransformer` class to use: + +| Key | Value | +|-----|-------| +| `transformer` | `NameOfTheTransformerClass` | + +__Example__: + +![transformer](documentation/transformer.png) + + +
+📑 Sample of the generated code in Swift (iOS) + +`gyro` will produce the following code. (In this example, attributes `attrDouble` and `attrInteger32` don't have a **transformer** key set in their UserInfo). + +`Shop+Decodable.swift`: + +```swift +/* DO NOT EDIT | Generated by gyro */ + +import protocol Decodable.Decodable +import Decodable + +extension Shop: Decodable { + + static func decode(_ json: Any) throws -> Shop { + let shop = Shop() + shop.attrDate = try Date.decode(json => "attrDate") + shop.attrDateCustom = try Date.decode(json => "attrDateCustom") + shop.attrDouble = try json => "attrDouble" + shop.attrInteger16 = try Int.decode(json => "attrInteger16") + shop.attrInteger32 = try json => "attrInteger32" + shop.attrInteger64 = try Int.decode(json => "attrInteger64") + return shop + } +} +``` + +`ShopMapper.swift`: + +```swift +/* DO NOT EDIT | Generated by gyro */ + +import ObjectMapper + +extension Shop: Mappable { + + // MARK: Initializers + convenience init?(_ map: Map) { + self.init() + } + + // MARK: Mappable + func mapping(map: Map) { + // MARK: Attributes + self.attrDate <- (map["attrDate"], ISO8601DateTransform()) + self.attrDateCustom <- (map["attrDateCustom"], CustomDateTransformer()) + self.attrDecimal <- (map["attrDecimal"], MPDecimalTransformer()) + self.attrDouble <- map["attrDouble"] + self.attrFloat <- (map["attrFloat"], MPDecimalTransformer()) + self.attrInteger16 <- (map["attrInteger16"], MPIntegerTransformer()) + self.attrInteger32 <- map["attrInteger32"] + self.attrInteger64 <- (map["attrInteger64"], MPIntegerTransformer()) + } +} + +``` +
+ diff --git a/bin/gyro b/bin/gyro index dfa79d3..f5db5fd 100755 --- a/bin/gyro +++ b/bin/gyro @@ -1,118 +1,125 @@ #!/usr/bin/env ruby -=begin -Copyright 2016 - Niji +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -if RUBY_VERSION < '2.0.0' - abort 'error: gyro requires Ruby 2 or higher.' -end +abort 'error: gyro requires Ruby 2 or higher.' if RUBY_VERSION < '2.0.0' require 'gyro' require 'optparse' +require 'pathname' dir = Dir.pwd options = { - :model => nil, - :android_dir => nil, - :package => nil, - :ios_dir => nil, - :ios_json => false, - :ios_framework => false, - :ios_swift => false + model: nil, + template: nil, + output: nil, + params: {} } -OptionParser.new do |opts| +parser = OptionParser.new do |opts| opts.banner = 'Usage: gyro [options]' - opts.on('-m PATH', '--model PATH', %q(Specify Interface Builder .xcdatamodel file)) do |path| - options[:model] = path - end - opts.on('-a PATH', '--android PATH', %q(Specify Android Realm model classes dir)) do |path| - options[:android_dir] = path + opts.on('-m PATH', '--model PATH', 'The .xcdatamodel file to use') do |xcdatamodel_path| + options[:model] = xcdatamodel_path end - opts.on('-p PATH', '--package PATH', %q(Specify Android Realm model classes package name)) do |path| - options[:package] = path + opts.on('-t DIR', '--template DIR', + 'Path to the template directory to use, or name of a template embedded in gyro', + '(see --list for available names)') do |path| + options[:template] = path end - opts.on('-i PATH', '--ios PATH', %q(Specify iOS Realm model classes dir)) do |path| - options[:ios_dir] = path + opts.on('-o DIR', '--output DIR', + 'Path to the output directory where to generate the model files') do |path| + options[:output] = path end - opts.on('-j', '--json', %q(Additionally generate Realm-JSON categories (Objective-C) or ObjectMapper artifacts (Swift))) do - options[:ios_json] = true + opts.on('-p KEY:VALUE', '--param KEY:VALUE', + 'Specify a custom parameter that can be used by the template.', + 'Can be repeated to add more parameters') do |params| + (k, *v) = params.split(':') + options[:params] = options[:params].merge(k.to_s => v.join(':').to_s) end - opts.on('-f', '--framework', %q(If you use CocoaPods Frameworks instead of static libraries)) do - options[:ios_framework] = true + opts.on('-l', '--list', 'List the names of all available templates provided by gyro') do + Gyro::Template.print_list + exit end - opts.on('-s', '--swift', %q(If you use Swift as iOS language)) do - options[:ios_swift] = true + opts.on('-i', '--info TEMPLATE', + 'Show information about the given template', + '(path to directory or name of an embedded template)') do |template| + Gyro::Template.print_infos(template) + exit end - opts.on('-n', '--nsnumber', %q(To generate NSNumbers instead of Int/BOOL/Float types)) do - options[:wrappers] = true + opts.on_tail('-h', '--help', 'Show this message') do + puts opts + exit 1 end - opts.on('-w', '--wrappers', %q(To generate Java primitive wrappers for optional fields instead of primitive types)) do - options[:wrappers] = true + opts.on_tail('-v', '--version', 'Show version') do + puts Gyro::VERSION + exit end - opts.on('-x', '--annotations', %q(To tag code with Android support annotations according to optional/non optional fields)) do - options[:annotations] = true - end - opts.on_tail('-h', '--help', %q(Show this message)) { puts opts; exit 1 } - opts.on_tail('-v', '--version', 'Show version') { puts Gyro::VERSION; exit } - opts.parse! +end + +begin + parser.parse!(ARGV) +rescue OptionParser::ParseError => e + Gyro::Log.error(e) + puts parser + exit 1 end if options[:model].nil? - Gyro::Log::info('No model provided, trying to find one in the local directory…') - options[:model] = Gyro.find_xcdatamodel(dir) - Gyro::Log::info("Unable to find any .xcdatamodel in #{dir}") if options[:model].nil? + Gyro::Log.info('No model provided, trying to find one in the local directory…') + options[:model] = Gyro::Parser::XCDataModel.find_in_dir(dir) + Gyro::Log.info("Unable to find any .xcdatamodel in #{dir}") if options[:model].nil? end if options[:model].nil? - Gyro::Error::exit_with_error('You need to specify .xcdatamodel path using --model option (see --help for more info)') + Gyro::Log.fail!('You need to specify .xcdatamodel path using --model option (see --help for more info)') else basename = File.basename(options[:model]) dirname = File.dirname(options[:model]) - Gyro::Log::success("Using #{basename} in #{dirname}") + Gyro::Log.success("Using #{basename} in #{dirname}") end -# Android -if options[:android_dir].nil? - Gyro::Log::info('You need to specify a dir using --android option to generate Android Realm model classes (see --help for more info)') -else - if Dir.exist?(options[:android_dir]) - if options[:package].nil? - Gyro::Log::info('You need to specify an Android package name using --package option (see --help for more info)') - else - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(options[:model]) - Gyro::Realm::Java::Generator.new(options[:android_dir], options[:package], xcdatamodel, options[:wrappers], options[:annotations]) - end - else - Gyro::Log::info('You need to specify a valid Android Realm model classes dir') - end +# Liquid Templates +if options[:template].nil? + # Generate JSON if no -t is specified + Gyro::Log.info('Note: You can specify a template using the --template option (see --help for more info)') + xcdatamodel = Gyro::Parser::XCDataModel::XCDataModel.new(options[:model]) + Gyro::Generator::Json.new(xcdatamodel) + exit end -# iOS -if options[:ios_dir].nil? - Gyro::Log::info('You need to specify a dir using --ios option to generate iOS Realm model classes (see --help for more info)') -else - if Dir.exist?(options[:ios_dir]) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(options[:model]) - if options[:ios_swift] - Gyro::Realm::Swift::Generator.new(options[:ios_dir], xcdatamodel, options[:ios_json]) - else - Gyro::Realm::ObjC::Generator.new(options[:ios_dir], xcdatamodel, options[:ios_json], options[:ios_framework], options[:wrappers]) - end - else - Gyro::Log::info('You need to specify a valid iOS Realm model classes dir') - end +template_dir = Gyro::Template.find(options[:template]) + +if options[:output].nil? + Gyro::Log.fail!('You need to specify output directory path using --output option (see --help for more info)') end + +output_dir = Pathname.new(options[:output]) + +unless output_dir.exist? + Gyro::Log.fail!("The output directory #{output_dir} does not exist. Please create it first.") +end + +puts <<-INFO.gsub(/ \|/, '') + | + |#=================================== + |# Template : #{template_dir} + |# Output Dir : #{output_dir} + |# Params : #{options[:params].inspect} + |#=================================== +INFO + +xcdatamodel = Gyro::Parser::XCDataModel::XCDataModel.new(options[:model]) +gen = Gyro::Generator::Liquid.new(template_dir, output_dir, options[:params]) +gen.generate(xcdatamodel) diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..582014b --- /dev/null +++ b/circle.yml @@ -0,0 +1,3 @@ +test: + post: + - bundle exec rubocop diff --git a/gyro.gemspec b/gyro.gemspec index c1f0da3..101c96f 100644 --- a/gyro.gemspec +++ b/gyro.gemspec @@ -4,21 +4,26 @@ Gem::Specification.new do |s| s.name = 'gyro' s.version = Gyro::VERSION s.date = '2017-04-10' - s.summary = "Generate Realm.io models for Swift, Java & ObjC from xcdatamodel" + s.summary = 'Generate Realm.io models for Swift, Java & ObjC from xcdatamodel' s.description = <<-DESC This tools allows you to use the visual Xcode editor to design your DataModels - using the xcdatamodel format (originally designed for CoreData) but then + using the xcdatamodel format (originally designed for CoreData) but then generate the code for Realm.io models for Swift, Java & ObjC from that xcdatamodel. This way you can take advantage of the xcdatamodel visual editor and Xcode integration while using Realm instead of CoreData. DESC - s.authors = ["NijiDigital", "Olivier Halligon", "François Ganard"] + s.authors = ['NijiDigital', 'Olivier Halligon', 'François Ganard'] s.email = 'contact@niji.fr' s.homepage = 'https://github.com/NijiDigital/gyro' s.license = 'Apache-2.0' - s.files = Dir["lib/**/*"] + Dir["bin/gyro"] + %w(README.md LICENSE) + Dir["documentation/"] + s.files = Dir['lib/**/*'] + Dir['bin/gyro'] + %w[README.md LICENSE] + Dir['documentation/**/*'] s.executables << 'gyro' s.required_ruby_version = '>= 2.0.0' + + s.add_dependency 'liquid', '~> 3.0' + s.add_dependency 'nokogiri', '~> 1.6.8' + + s.add_development_dependency 'rspec', '~> 3.5' end diff --git a/lib/gyro.rb b/lib/gyro.rb index 0639786..38da045 100644 --- a/lib/gyro.rb +++ b/lib/gyro.rb @@ -1,27 +1,21 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. require 'gyro/version' -require 'gyro/xcdatamodel/parser' -require 'gyro/realm/java/generator' -require 'gyro/realm/objc/generator' -require 'gyro/realm/swift/generator' +require 'gyro/parser/xcdatamodel' +require 'gyro/generator/json' +require 'gyro/generator/liquid' -require 'gyro/utils/log' -require 'gyro/utils/file_utils' -require 'gyro/utils/string_xcdatamodel' -require 'gyro/utils/error' \ No newline at end of file +require 'gyro/log' diff --git a/lib/gyro/generator/json.rb b/lib/gyro/generator/json.rb new file mode 100644 index 0000000..29d630b --- /dev/null +++ b/lib/gyro/generator/json.rb @@ -0,0 +1,30 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'json' +require 'gyro/parser/xcdatamodel' + +module Gyro + module Generator + # Generates the JSON representation of the input datamodel + # + class Json + # PUBLIC METHODS ####################################################### + def initialize(xcdatamodel) + Gyro::Log.title('Generating JSON') + puts JSON.pretty_generate(xcdatamodel.to_h) + end + end + end +end diff --git a/lib/gyro/generator/liquid.rb b/lib/gyro/generator/liquid.rb new file mode 100644 index 0000000..d641b2a --- /dev/null +++ b/lib/gyro/generator/liquid.rb @@ -0,0 +1,22 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'liquid' +require 'pathname' + +require 'gyro/parser/xcdatamodel' +require 'gyro/template' +require 'gyro/generator/liquid/liquid' +require 'gyro/generator/liquid/whitespace_patch' +require 'gyro/generator/liquid/filters' diff --git a/lib/gyro/generator/liquid/filters.rb b/lib/gyro/generator/liquid/filters.rb new file mode 100644 index 0000000..cfb5f42 --- /dev/null +++ b/lib/gyro/generator/liquid/filters.rb @@ -0,0 +1,53 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Gyro + module Generator + # Declare some custom Liquid Filters used by the template, then render it + # + module LiquidFilters + def escape_quotes(input) + input.gsub('"', '\"') + end + + def snake_to_camel_case(input) + input.split('_').map(&:capitalize).join + end + + def snake_case(input) + input.gsub(/::/, '/') + .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + .gsub(/([a-z\d])([A-Z])/, '\1_\2') + .tr('-', '_') + .downcase + end + + def uncapitalize(input) + input_strip = input.strip + input_strip[0, 1].downcase + input_strip[1..-1] + end + + def titleize(input) + input_strip = input.strip + input_strip[0, 1].upcase + input_strip[1..-1] + end + + def delete_objc_prefix(input) + i = 0 + i += 1 while i < input.length - 1 && /[[:upper:]]/.match(input[i + 1]) + input[i..input.length] + end + end + end +end diff --git a/lib/gyro/generator/liquid/liquid.rb b/lib/gyro/generator/liquid/liquid.rb new file mode 100644 index 0000000..b60c0ec --- /dev/null +++ b/lib/gyro/generator/liquid/liquid.rb @@ -0,0 +1,124 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Gyro + module Generator + # Generates arbitrary output from the input datamodel, using a Liquid template provided by the user + # + class Liquid + attr_accessor :params, :output_dir + + # PUBLIC METHODS ####################################################### + + # rubocop:disable Metrics/AbcSize + def initialize(template_dir, output_dir, params) + Gyro::Log.title('Generating Model') + + @params = params + @output_dir = Pathname.new(output_dir) + + # Define Template path for Liquid file system to use Include Tag + ::Liquid::Template.file_system = ::Liquid::LocalFileSystem.new(template_dir) + + @entity_template = load_template(template_dir + 'entity.liquid', false) + @entity_filename_template = load_template(template_dir + 'entity_filename.liquid', true) + @enum_template = load_template(template_dir + 'enum.liquid', false) + enum_fn_tpl = template_dir + 'enum_filename.liquid' + enum_fn_tpl = template_dir + 'filename.liquid' unless enum_fn_tpl.exist? + @enum_filename_template = load_template(enum_fn_tpl, true) + end + # rubocop:enable Metrics/AbcSize + + def generate(xcdatamodel) + generate_entities(xcdatamodel) + Gyro::Log.success('Model objects are generated !') + end + + private ################################################################ + + def load_template(template_path, prevent_return_line) + unless template_path.exist? + Gyro::Log.fail!('Bad template directory content ! Your template needs a ' + template_path.to_s + ' file') + end + template_path_string = template_path.read + if prevent_return_line && template_path_string.include?("\n") + msg = 'The given template ' + template_path.to_s + ' contains return line(s). This can lead to side effets.' + Gyro::Log.error(msg) + end + ::Liquid::Template.parse(template_path_string) + end + + def generate_entities(xcdatamodel) + xcdatamodel.to_h['entities'].each do |entity| + entity_context = { 'params' => @params, 'entity' => entity } + # Rendering template using entity and params context + output = render_entity(entity_context) + # Don't generate empty output + next if output.delete("\n").empty? + + filename_context = { 'params' => @params, 'name' => entity['name'] } + # Rendering filename template using entity name and params context + filename = render_filename(filename_context) + Gyro::Log.success("#{filename} is created !") + # Write model object + File.write(@output_dir + filename, output) + # Generate model object enums + generate_enums(entity['attributes']) + end + end + + def generate_enums(attributes) + enums = [] + attributes.each do |attribute| + enum_type = attribute['enum_type'] + next if enums.include?(enum_type) || enum_type.empty? + enums.push(enum_type) + + enum_context = { 'params' => @params, 'attribute' => attribute } + # Rendering enum template using attribute and params context + output = render_enum(enum_context) + # Don't generate empty output + next if output.delete("\n").empty? + + generate_enum(enum_type, output) + end + end + + def generate_enum(enum_name, output) + # Rendering enum filename template using enum name and params context + enum_filename_context = { 'params' => @params, 'name' => enum_name } + enum_filename = render_enum_filename(enum_filename_context) + File.write(@output_dir + enum_filename, output) + end + + def render_entity(context) + @entity_template.render(context, filters: [Gyro::Generator::LiquidFilters]) + .gsub(/^ +$/, '') + end + + def render_filename(context) + @entity_filename_template.render(context).chomp + end + + def render_enum(context) + @enum_template.render(context, filters: [Gyro::Generator::LiquidFilters]) + .gsub(/^ +$/, '') + end + + def render_enum_filename(context) + @enum_filename_template.render(context).chomp + end + end + end +end diff --git a/lib/gyro/generator/liquid/whitespace_patch.rb b/lib/gyro/generator/liquid/whitespace_patch.rb new file mode 100644 index 0000000..d141439 --- /dev/null +++ b/lib/gyro/generator/liquid/whitespace_patch.rb @@ -0,0 +1,61 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'liquid' + +if Gem::Version.new(Liquid::VERSION) < Gem::Version.new('4.0.0') + module Gyro + module Generator + # This allows to support whitespace trimming (which is only supported in Liquid 4) when using Liquid 3.0 + # It works by patching Liquid::Template using ruby's `Module#prepend` feature + # See http://stackoverflow.com/a/4471202/803787 for more info on Monkey-Patching in Ruby + # + module LiquidWhitespacePatch + # Patch for Liquid::Template class + # + module Template + def parse(source, options = {}) + super(source.gsub(/\s*{%-/, "\v{%").gsub(/-%}\s*/, "%}\v"), options) + end + + def render(*params) + super(*params).delete("\v") + end + end + + # Patch for Liquid's String extension + # + module String + def to_liquid + super.delete("\v") + end + end + end + end + end + + module Liquid + # Monkey-Patch Liquid::Template class + # + class Template + prepend Gyro::Generator::LiquidWhitespacePatch::Template + end + end + + # Monkey-Patch String + # + class String + prepend Gyro::Generator::LiquidWhitespacePatch::String + end +end diff --git a/lib/gyro/log.rb b/lib/gyro/log.rb new file mode 100644 index 0000000..1bbcf73 --- /dev/null +++ b/lib/gyro/log.rb @@ -0,0 +1,46 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Gyro + # Print nice and colored output for various error/success/title messages of Gyro + # + module Log + @quiet = false + def self.quiet=(value) + @quiet = value + end + + def self.title(str) # bg yellow + puts "\n\e[44;37m#{str}\e[0m" unless @quiet + end + + def self.error(str) + puts "\e[1;31m! #{str}\e[0m" unless @quiet + end + + def self.info(str) + puts "\e[1;33m> #{str}\e[0m" unless @quiet + end + + def self.success(str) + puts "\e[1;32m√ #{str}\e[0m" unless @quiet + end + + def self.fail!(message, stacktrace: false) + Gyro::Log.error message + raise message if stacktrace + exit 1 + end + end +end diff --git a/lib/gyro/parser/xcdatamodel.rb b/lib/gyro/parser/xcdatamodel.rb new file mode 100644 index 0000000..f9900b6 --- /dev/null +++ b/lib/gyro/parser/xcdatamodel.rb @@ -0,0 +1,20 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'nokogiri' + +require 'gyro/parser/xcdatamodel/xcdatamodel' +require 'gyro/parser/xcdatamodel/attribute' +require 'gyro/parser/xcdatamodel/relationship' +require 'gyro/parser/xcdatamodel/entity' diff --git a/lib/gyro/parser/xcdatamodel/attribute.rb b/lib/gyro/parser/xcdatamodel/attribute.rb new file mode 100644 index 0000000..4ea5c43 --- /dev/null +++ b/lib/gyro/parser/xcdatamodel/attribute.rb @@ -0,0 +1,129 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Gyro + module Parser + module XCDataModel + # One Attribute in an Entity of the xcdatamodel + # + class Attribute + attr_accessor :entity_name, :name, :type, :optional, :indexed, :default + attr_accessor :realm_ignored, :realm_read_only, :enum_type, :enum_values + attr_accessor :json_key_path, :json_values, :transformer, :comment, :support_annotation + + alias optional? optional + alias indexed? indexed + alias realm_ignored? realm_ignored + + # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + def initialize(attribute_xml, entity_name) + @entity_name = entity_name + @name = attribute_xml.xpath('@name').to_s + @optional = attribute_xml.xpath('@optional').to_s == 'YES' + @indexed = attribute_xml.xpath('@indexed').to_s == 'YES' + @default = attribute_xml.xpath('@defaultValueString').to_s + @type = attribute_xml.xpath('@attributeType').to_s.downcase.tr(' ', '_').to_sym + @realm_ignored = !Gyro::Parser::XCDataModel.user_info(attribute_xml, 'realmIgnored').empty? + @realm_read_only = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'realmReadOnly') + @enum_type = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'enumType') + @enum_values = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'enumValues').split(',') + @json_key_path = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'JSONKeyPath') + @json_values = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'JSONValues').split(',') + @transformer = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'transformer').strip + @comment = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'comment') + @support_annotation = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'supportAnnotation') + search_for_error + end + + def to_h + { + 'entity_name' => entity_name, 'name' => name, + 'type' => type.to_s, + 'optional' => optional, + 'indexed' => indexed, + 'default' => default, + 'realm_ignored' => realm_ignored, 'realm_read_only' => realm_read_only, + 'enum_type' => enum_type, 'enum_values' => enum_values, + 'json_key_path' => json_key_path, 'json_values' => json_values, + 'transformer' => transformer, 'need_transformer' => need_transformer?, + 'comment' => comment, + 'support_annotation' => support_annotation, + 'is_decimal' => decimal?, 'is_integer' => integer?, 'is_number' => number?, 'is_bool' => bool? + } + end + # rubocop:enable Metrics/AbcSize, Metrics/MethodLength + + def enum? + !@enum_type.empty? + end + + def read_only? + !@realm_read_only.empty? + end + + def default? + !@default.empty? + end + + def to_s + items = [ + "name=#{@name}", + "type=#{@type}", + "optional=#{@optional}", + "default=#{@default}", + "indexed=#{@indexed}" + ] + "\tAttribute => " + items.join(' | ') + "\n" + end + + def decimal? + (@type == :decimal) || (@type == :double) || (@type == :float) + end + + def integer? + (@type == :integer_16) || (@type == :integer_32) || (@type == :integer_64) + end + + def number? + decimal? || integer? + end + + def bool? + @type == :boolean + end + + def need_transformer? + !@enum_type.empty? || (@type == :boolean) || (@type == :date) || !@transformer.empty? + end + + private ################################################################ + + def search_for_error + # rubocop:disable Style/GuardClause + if @type == :undefined || @type.empty? + msg = %(The attribute "#{@name}" from "#{@entity_name}" has no type - please fix it) + Gyro::Log.fail!(msg, stacktrace: true) + end + if !@json_key_path.empty? && !@enum_values.empty? && (@enum_values.size != @json_values.size) + message = %(The attribute "#{@name}" from "#{@entity_name}" is wrongly annotated:) + + %(when declaring an type with enum and JSONKeyPath, you must have the same number of items) + + %(in the 'enumValues' and 'JSONValues' annotations.) + Gyro::Log.fail!(message, stacktrace: true) + end + # rubocop:enable Style/GuardClause + end + end + end + end +end diff --git a/lib/gyro/parser/xcdatamodel/entity.rb b/lib/gyro/parser/xcdatamodel/entity.rb new file mode 100644 index 0000000..0f465af --- /dev/null +++ b/lib/gyro/parser/xcdatamodel/entity.rb @@ -0,0 +1,195 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Gyro + module Parser + module XCDataModel + # One Entity in the xcdatamodel + # + class Entity + attr_accessor :name, :parent, :abstract, :attributes, :relationships, :identity_attribute, :comment + alias abstract? abstract + + # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + def initialize(entity_xml) + @name = entity_xml.xpath('@name').to_s + @parent = entity_xml.xpath('@parentEntity').to_s + @abstract = entity_xml.xpath('@isAbstract').to_s == 'YES' ? true : false + @clean = false + @identity_attribute = Gyro::Parser::XCDataModel.user_info(entity_xml, 'identityAttribute') + @comment = Gyro::Parser::XCDataModel.user_info(entity_xml, 'comment') + @attributes = {} + @relationships = {} + load_entity(entity_xml) + end + + def to_h + { + 'attributes' => attributes.values.map(&:to_h), + 'relationships' => relationships.values.map(&:to_h), + 'name' => name, + 'parent' => parent, + 'abstract' => abstract, + 'identity_attribute' => identity_attribute, + 'comment' => comment, + 'has_no_inverse_relationship' => no_inverse_relationship?, + 'has_ignored' => ignored_attributes_relationships?, 'has_required' => required_attributes?, + 'has_primary_key' => primary_key?, 'has_indexed_attributes' => indexed_attributes?, + 'has_json_key_path' => json_key_paths?, 'has_enum_attributes' => enum_attributes?, + 'has_custom_transformers' => custom_transformers?, 'need_transformer' => need_transformer?, + 'has_bool_attributes' => bool_attributes?, + 'has_number_attributes' => number_attributes?, + 'has_date_attribute' => date_attributes?, + 'has_list_relationship' => list_relationships?, + 'has_list_attributes' => list_attributes?, + 'has_only_inverse' => only_inverse_relationships? + } + end + # rubocop:enable Metrics/AbcSize, Metrics/MethodLength + + def to_s + "\nEntity => #{@name}\n" + + @attributes.map { |_, attr| attr.to_s } + + @relationships.map { |_, rel| rel.to_s } + end + + def used_as_list_by_other?(entities) + entities.any? do |_, entity| + entity.relationships.any? do |_, relationship| + (relationship.inverse_type == @name) && (relationship.type == :to_many) + end + end + end + + def list_attributes?(include_inverse = false) + @relationships.any? do |_, relationship| + (relationship.type == :to_many) && (include_inverse ? true : !relationship.inverse?) + end + end + + def no_inverse_relationship? + @relationships.none? { |_, relationship| relationship.inverse? } + end + + def ignored_attributes? + @attributes.any? { |_, attribute| attribute.realm_ignored? } + end + + def ignored_relationships? + @relationships.any? { |_, relationship| relationship.realm_ignored? } + end + + def ignored_attributes_relationships? + ignored_attributes? || ignored_relationships? + end + + def primary_key? + !@identity_attribute.empty? + end + + def required_attributes? + @attributes.any? { |_, attribute| required?(attribute) } + end + + def required?(attribute) + return false if attribute.optional? + return true unless primary_key? + return true if primary_key? && !attribute.name.eql?(identity_attribute) + end + + def default_value?(attribute) + attribute.name != @identity_attribute + end + + def indexed_attributes? + @attributes.any? { |_, attribute| attribute.indexed? } + end + + def json_key_paths? + @attributes.any? do |_, attribute| + !attribute.json_key_path.empty? + end || @relationships.any? do |_, relationship| + !relationship.inverse? && !relationship.json_key_path.empty? + end + end + + def enum_attributes? + @attributes.any? { |_, attribute| !attribute.enum_type.empty? } + end + + def transformers + transformers = Set.new + @attributes.each do |_, attribute| + transformers.add attribute.transformer unless attribute.transformer.empty? + end + transformers + end + + def custom_transformers? + @attributes.any? { |_, attribute| !attribute.transformer.empty? } + end + + def need_transformer? + enum_attributes? || bool_attributes? || custom_transformers? || date_attributes? + end + + def bool_attributes? + @attributes.any? { |_, attribute| attribute.type == :boolean } + end + + NUMBER_TYPES = %i[integer_16 integer_32 integer_64 decimal double float].freeze + def number_attributes? + @attributes.any? do |_, attribute| + attribute.enum_type.empty? && NUMBER_TYPES.include?(attribute.type) + end + end + + def date_attributes? + @attributes.any? { |_, attribute| attribute.type == :date } + end + + def list_relationships? + @relationships.any? { |_, relationship| !relationship.destination.empty? } + end + + def only_inverse_relationships? + @relationships.all? { |_, relationship| relationship.inverse? } + end + + private ################################################################ + + def load_entity(entity_xml) + load_attributes(entity_xml) + load_relationships(entity_xml) + end + + def load_attributes(entity_xml) + entity_xml.xpath('attribute').each do |node| + attribute = Attribute.new(node, @name) + if attribute.type != 'Transformable' + @attributes[attribute.name] = attribute + end + end + end + + def load_relationships(entity_xml) + entity_xml.xpath('relationship').each do |node| + relationship = Relationship.new(node, @name) + @relationships[relationship.name] = relationship + end + end + end + end + end +end diff --git a/lib/gyro/parser/xcdatamodel/relationship.rb b/lib/gyro/parser/xcdatamodel/relationship.rb new file mode 100644 index 0000000..b36be1a --- /dev/null +++ b/lib/gyro/parser/xcdatamodel/relationship.rb @@ -0,0 +1,84 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Gyro + module Parser + module XCDataModel + # One Relationship between attributes in the xcdatamodel + # + class Relationship + attr_accessor :entity_name, :name, :type, :optional, :deletion_rule + attr_accessor :inverse_name, :inverse_type, :json_key_path, :support_annotation + attr_accessor :realm_ignored + attr_accessor :destination + + alias realm_ignored? realm_ignored + + # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + def initialize(relationship_xml, entity_name) + @entity_name = entity_name + @name = relationship_xml.xpath('@name').to_s + @optional = relationship_xml.xpath('@optional').to_s == 'YES' ? true : false + @deletion_rule = relationship_xml.xpath('@deletionRule').to_s + @inverse_name = relationship_xml.xpath('@inverseName').to_s + @inverse_type = relationship_xml.xpath('@destinationEntity').to_s + @json_key_path = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'JSONKeyPath') + @realm_ignored = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'realmIgnored').empty? ? false : true + @support_annotation = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'supportAnnotation') + load_type(relationship_xml) + @destination = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'destination') + search_for_error + end + + def to_h + { 'entity_name' => entity_name, 'name' => name, 'type' => type.to_s, + 'optional' => optional, 'deletion_rule' => deletion_rule, + 'inverse_name' => inverse_name, 'inverse_type' => inverse_type, + 'json_key_path' => json_key_path, 'support_annotation' => support_annotation, + 'realm_ignored' => realm_ignored, 'destination' => destination, 'inverse' => inverse? } + end + # rubocop:enable Metrics/AbcSize, Metrics/MethodLength + + def to_s + "\tRelationship => name=#{@name} | type=#{@type} | optional=#{@optional} | deletion_rule=#{@deletion_rule}\n" + end + + def inverse? + @name.end_with?('_') + end + + private ################################################################ + + def load_type(relationship_xml) + max_count = relationship_xml.xpath('@maxCount').to_s + @type = !max_count.nil? && (max_count == '1') ? :to_one : :to_many + end + + def search_for_error + # rubocop:disable Style/GuardClause + if inverse_type.empty? && destination.empty? + message = %(The relationship "#{@name}" from "#{@entity_name}" is wrong - please fix it) + Gyro::Log.fail!(message, stacktrace: true) + end + if !destination.empty? && type != :to_many + message = %(The relationship "#{@name}" from "#{@entity_name}" is wrong - ) + + %(please set a 'No Value' relationship as 'To Many') + Gyro::Log.fail!(message, stacktrace: true) + end + # rubocop:enable Style/GuardClause + end + end + end + end +end diff --git a/lib/gyro/parser/xcdatamodel/xcdatamodel.rb b/lib/gyro/parser/xcdatamodel/xcdatamodel.rb new file mode 100644 index 0000000..76ff3e1 --- /dev/null +++ b/lib/gyro/parser/xcdatamodel/xcdatamodel.rb @@ -0,0 +1,65 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Gyro + module Parser + # Parser for CoreData's xcdatamodel files + # + module XCDataModel + def self.find_in_dir(dir) + Dir.chdir(dir) do + files = Dir.glob('*.xcdatamodel') + files.first.nil? ? nil : File.expand_path(files.first, dir) + end + end + + def self.user_info(xml, key) + xml.xpath("userInfo/entry[@key='#{key}']/@value").to_s + end + + # Represents the whole xcdatamodel file struture, once parsed + # + class XCDataModel + attr_accessor :entities + + def initialize(xcdatamodel_dir) + contents_file = File.join(xcdatamodel_dir, 'contents') + Gyro::Log.fail!('Unable to find contents of xcdatamodel', stacktrace: true) unless File.exist?(contents_file) + @entities = {} + file = File.open(contents_file) + document_xml = Nokogiri::XML(file).remove_namespaces! + file.close + load_entities(document_xml) + end + + def to_h + { 'entities' => entities.values.map(&:to_h) } + end + + def to_s + @entities.values.map(&:to_s).join + end + + private + + def load_entities(document_xml) + document_xml.xpath('//entity').each do |node| + entity = Entity.new(node) + @entities[entity.name] = entity + end + end + end + end + end +end diff --git a/lib/gyro/realm/java/converter.rb b/lib/gyro/realm/java/converter.rb deleted file mode 100644 index 61deff8..0000000 --- a/lib/gyro/realm/java/converter.rb +++ /dev/null @@ -1,63 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Realm - module Java - module Converter - - TYPES = { - :integer_16 => 'short', - :integer_32 => 'int', - :integer_64 => 'long', - :decimal => 'double', - :double => 'double', - :float => 'float', - :string => 'String', - :boolean => 'boolean', - :date => 'Date', - :binary => 'byte[]' - } - - WRAPPER_TYPES = { - :integer_16 => 'Short', - :integer_32 => 'Integer', - :integer_64 => 'Long', - :decimal => 'Double', - :double => 'Double', - :float => 'Float', - :string => 'String', - :boolean => 'Boolean', - :date => 'Date', - :binary => 'Byte[]' - } - - def convert_type(type, useWrapperClass) - if (useWrapperClass) - WRAPPER_TYPES[type] - else - TYPES[type] - end - end - - def is_primitive(type_str) - TYPES.has_value?(type_str) and type_str != "String" and type_str != "Date" - end - - end - end - end -end diff --git a/lib/gyro/realm/java/enum_generator.rb b/lib/gyro/realm/java/enum_generator.rb deleted file mode 100644 index 914a345..0000000 --- a/lib/gyro/realm/java/enum_generator.rb +++ /dev/null @@ -1,124 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Realm - module Java - module EnumGenerator - - # INCLUDES ############################################################# - include Templates - - # PUBLIC METHODS ####################################################### - - def generate_enums(path, package, attributes, support_annotations = false) - enums = Array.new - attributes.each do |_, attribute| - if attribute.enum? and !enums.include?(attribute.enum_type) - enum_type = attribute.enum_type.delete_objc_prefix - enums.push(enum_type) - generate_enum(path, package, enum_type, attribute.enum_values, attribute.json_values, support_annotations) - end - end - end - - def generate_enum_getter_and_setter(enum_type, attribute_name, support_annotations) - getter = String.new - setter = String.new - getter << ' ' + '@android.support.annotation.Nullable' + "\n" if support_annotations - getter << ' public ' + enum_type + ' get'+ attribute_name.capitalize_first_letter + 'Enum() {' + "\n" + - ' ' + 'return '+ enum_type + '.get(get' + attribute_name.capitalize_first_letter + '());' + "\n" + - ' ' + '}' + "\n" - setter << ' ' + 'public void set'+ attribute_name.capitalize_first_letter + 'Enum(' - setter << '@android.support.annotation.NonNull ' if support_annotations - setter << 'final ' + enum_type + ' ' + attribute_name +') {' + "\n" + - ' ' + 'this.' + attribute_name + ' = ' + attribute_name + '.getJsonValue();' + "\n" + - ' ' + '}' + "\n" - getter + "\n" + setter - end - - private ################################################################# - - def generate_enum(path, package, enum_name, enum_values, json_values, support_annotations) - enum_file = String.new - enum_file << PACKAGE_TEMPLATE%[package] + "\n\n" - enum_file << GENERATED_MESSAGE + "\n\n" - enum_file << ENUM_TEMPLATE%[enum_name] + "\n\n" - json_values = get_json_values(enum_values, json_values) - if enum_values.length != 0 - (0..enum_values.length - 1).each { |idx| - gson_value = json_values[idx] - enum_value = generate_enum_string(enum_values[idx], gson_value) - enum_file << (idx != enum_values.length - 1 ? enum_value + ",\n" : enum_value + ";\n") - } - enum_file << "\n" ' ' + FINAL_ATTRIBUTE_TEMPLATE%%w(String jsonValue) + "\n\n" - enum_file << generate_enum_gson_constructor(enum_name) + "\n" - enum_file << generate_static_gson_getter(enum_name, support_annotations) + "\n" - enum_file << generate_gson_getter(support_annotations) - enum_file << '}' + "\n" - Gyro.write_file_with_name(path, JAVA_FILE_TEMPLATE%[enum_name], enum_file) - end - end - - def generate_enum_string(enum_value, gson_value) - enum_value = enum_value.delete_objc_prefix.camel_case - gson_annotation = gson_value.empty? ? '' : ENUM_JSON_VALUE%[gson_value] - ' ' + enum_value + gson_annotation - end - - def generate_enum_gson_constructor(enum_name) - ' ' + enum_name +'(final String jsonValue) {' + "\n" + - ' ' + 'this.jsonValue = jsonValue;' + "\n" + - ' ' + '}' + "\n" - end - - # Methods to bypass enum restriction in Realm - def generate_static_gson_getter(enum_name, support_annotations) - getter = String.new - getter << ' @android.support.annotation.Nullable' + "\n" if support_annotations - getter << ' public static ' + enum_name + ' get(final String jsonValue) {' + "\n" + - ' ' + 'for (final ' + enum_name + ' type : ' + enum_name + '.values()) {' + "\n" + - ' ' + 'if (type.getJsonValue().equals(jsonValue)) {' + "\n" + - ' ' + 'return type;' + "\n" + - ' ' + '}'+ "\n" + - ' ' + '}' + "\n" + - ' ' + 'return null;' + "\n" + - ' ' + '}' + "\n" - getter - end - - def generate_gson_getter(support_annotations) - getter = String.new - getter << ' @android.support.annotation.NonNull' + "\n" if support_annotations - getter << ' ' + 'public String getJsonValue() {' + "\n" + - ' ' + 'return jsonValue;' + "\n" + - ' ' + '}' + "\n" - getter - end - - def get_json_values(enum_values, json_values) - if json_values.empty? - enum_values.each { |value| - json_values << value.delete_objc_prefix.underscore - } - end - json_values - end - - end - end - end -end diff --git a/lib/gyro/realm/java/generator.rb b/lib/gyro/realm/java/generator.rb deleted file mode 100644 index d3b0e01..0000000 --- a/lib/gyro/realm/java/generator.rb +++ /dev/null @@ -1,180 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -require 'gyro/xcdatamodel/parser' -require 'gyro/realm/java/templates' -require 'gyro/realm/java/converter' -require 'gyro/realm/java/enum_generator' - -module Gyro - module Realm - module Java - - class Generator - - # INCLUDES ############################################################# - - include Gyro::XCDataModel::Parser - include Converter - include EnumGenerator - include Templates - - # PUBLIC METHODS ####################################################### - - def initialize(path, package_name, xcdatamodel, use_wrappers = false, support_annotations = false) - puts "\n" - Gyro::Log::title('Android Realm') - xcdatamodel.entities.each do |_, entity| - unless entity.abstract? - Gyro::Log::success("Generating entity #{entity.name}...") - generate_class(path, package_name, entity, use_wrappers, support_annotations) - end - end - end - - private ################################################################ - - def generate_class(path, package, entity, use_wrappers, support_annotations) - class_file = String.new - entity.name = entity.name.delete_objc_prefix - generate_header(class_file, package, entity) - generate_attributes(class_file, entity.attributes, entity.relationships, entity.identity_attribute, use_wrappers, support_annotations) - generate_footer(class_file) - Gyro.write_file_with_name(path, JAVA_FILE_TEMPLATE%[entity.name], class_file) - generate_enums(path, package, entity.attributes, support_annotations) - end - - def generate_header(class_file, package, entity) - class_file << PACKAGE_TEMPLATE%[package] + "\n\n" - class_file << IMPORT_GSON + "\n\n" if entity.has_json_key_path? - class_file << IMPORT_DATE + "\n" if entity.has_date_attribute? - class_file << IMPORT_LIST + "\n" if entity.has_list_relationship? - class_file << "\n" if entity.has_date_attribute? or entity.has_list_relationship? - class_file << IMPORT_REALM_LIST + "\n" if entity.has_list_attributes? - class_file << IMPORT_REALM_OBJECT + "\n" - class_file << IMPORT_REALM_IGNORE + "\n" if entity.has_ignored? or entity.has_enum_attributes? - class_file << IMPORT_REALM_INDEX + "\n" if entity.has_indexed_attributes? - class_file << IMPORT_REALM_PRIMARY_KEY + "\n" if entity.has_primary_key? - class_file << "\n" if class_file != PACKAGE_TEMPLATE%[package] - class_file << GENERATED_MESSAGE + "\n\n" - class_file << CLASS_COMMENT_TEMPLATE%[entity.comment] + "\n" unless entity.comment.empty? - class_file << CLASS_TEMPLATE%[entity.name] + "\n\n" - class_file << generate_constants(entity) - end - - def generate_constants(entity) - attribute_constants = String.new - unless entity.attributes.empty? - attribute_constants << ' ' + ATTRIBUTE_CONSTANTS + "\n" - entity.attributes.each do |_, attribute| - unless attribute.realm_ignored? or attribute.read_only? - attribute_constants << ' ' + ATTRIBUTE_COMMENT_TEMPLATE%[attribute.comment] + "\n" unless attribute.comment.empty? - attribute_constants << ' ' + CONSTANT_TEMPLATE%[attribute.name.underscore.upcase, attribute.name] + "\n" - end - end - attribute_constants << ' ' + '}'+ "\n\n" - end - relationship_constants = String.new - if not entity.relationships.empty? and not entity.has_only_inverse? - relationship_constants << ' ' + RELATIONSHIP_CONSTANTS + "\n" - entity.relationships.each do |_, relationship| - relationship_constants << ' ' + CONSTANT_TEMPLATE%[relationship.name.underscore.upcase, relationship.name] + "\n" unless relationship.inverse? - end - relationship_constants << ' ' + '}'+ "\n\n" - end - attribute_constants + relationship_constants - end - - def generate_footer(class_file) - class_file << '}' + "\n" - end - - def generate_attributes(class_file, attributes, relationships, primary_key, use_wrappers, support_annotations) - # "NORMAL" ATTRIBUTES - (attributes_string, getters_and_setters_string) = write_attributes(attributes, primary_key, use_wrappers, support_annotations) - # "RELATIONSHIP" ATTRIBUTES - relationships.each do |_, relationship| - unless relationship.inverse? - if relationship.destination.empty? - type_without_prefix = relationship.inverse_type.delete_objc_prefix - type = relationship.type == :to_many ? REALM_LIST_TEMPLATE%[type_without_prefix] : type_without_prefix - name = relationship.name - else - type = LIST_TEMPLATE%[relationship.destination] - name = relationship.name - end - attributes_string << ' ' + IGNORED_ANNOTATION + "\n" if relationship.realm_ignored? - attributes_string << ' ' + GSON_ANNOTATION%[relationship.json_key_path]+ "\n" unless relationship.json_key_path.empty? - attributes_string << ' ' + ATTRIBUTE_TEMPLATE%[type, name] + "\n" - getters_and_setters_string << "\n" unless getters_and_setters_string.empty? - getters_and_setters_string << generate_getter_and_setter(type, name, (support_annotations and relationship.optional), (support_annotations and !relationship.optional), relationship.support_annotation) - end - end - class_file << attributes_string + "\n" + getters_and_setters_string - end - - def write_attributes(attributes, primary_key, use_wrappers, support_annotations) - attributes_string = String.new - getters_and_setters_string = String.new - attributes.each_with_index do |(_, attribute), idx| - unless attribute.read_only? - name = attribute.name - type = attribute.enum? ? 'String' : convert_type(attribute.type, (use_wrappers and attribute.optional)) - if type - # Realm annotations - attributes_string << ' ' + PRIMARY_KEY_ANNOTATION + "\n" if name == primary_key - attributes_string << ' ' + INDEXED_ANNOTATION + "\n" if attribute.indexed - attributes_string << ' ' + IGNORED_ANNOTATION + "\n" if attribute.realm_ignored? or attribute.enum? - if attribute.enum? - ignored_type = attribute.enum? ? attribute.enum_type.delete_objc_prefix : type - ignored_name = attribute.enum? ? name + 'Enum' : name - attributes_string << ' ' + ATTRIBUTE_TEMPLATE%[ignored_type, ignored_name] + "\n" - end - attributes_string << ' ' + GSON_ANNOTATION%[attribute.json_key_path]+ "\n" unless attribute.json_key_path.empty? - attributes_string << ' ' + SUPPORT_ANNOTATION%[attribute.support_annotation] + "\n" unless attribute.support_annotation.empty? - attributes_string << ' ' + ATTRIBUTE_TEMPLATE%[type, name] + "\n" - end - getters_and_setters_string << generate_getter_and_setter(type, name, (support_annotations and ((use_wrappers and attribute.optional) or (attribute.enum? and attribute.optional))), (support_annotations and ((!is_primitive(type) and !attribute.optional) or (attribute.enum? and !attribute.optional))), attribute.support_annotation) - getters_and_setters_string << "\n" + generate_enum_getter_and_setter(attribute.enum_type.delete_objc_prefix, name, support_annotations) if attribute.enum? - getters_and_setters_string << "\n" if idx != attributes.count - 1 - end - end - return attributes_string, getters_and_setters_string - end - - def generate_getter_and_setter(type, name, nullable, nonnull, support_annotation) - getter_setter = String.new - getter_setter << ' ' + SUPPORT_ANNOTATION%['Nullable'] + "\n" if nullable - getter_setter << ' ' + SUPPORT_ANNOTATION%['NonNull'] + "\n" if nonnull - getter_setter << ' ' + SUPPORT_ANNOTATION%[support_annotation] + "\n" unless support_annotation.empty? - getter_setter << ' ' + 'public ' + type + ' get' + name.capitalize_first_letter + '() {' + "\n" - getter_setter << ' ' + 'return '+ name + ';' + "\n" - getter_setter << ' ' + '}' + "\n\n" - getter_setter << ' ' + 'public void set' + name.capitalize_first_letter + '(' - getter_setter << SUPPORT_ANNOTATION%['Nullable'] + ' ' if nullable - getter_setter << SUPPORT_ANNOTATION%['NonNull'] + ' ' if nonnull - getter_setter << SUPPORT_ANNOTATION%[support_annotation] + ' ' unless support_annotation.empty? - getter_setter << 'final ' + type + ' ' + name + ') {' + "\n" - getter_setter << ' ' + 'this.' + name + ' = ' + name + ';' + "\n" - getter_setter << ' ' + '}' + "\n" - getter_setter - end - - end - - end - end -end diff --git a/lib/gyro/realm/java/templates.rb b/lib/gyro/realm/java/templates.rb deleted file mode 100644 index 4a318d6..0000000 --- a/lib/gyro/realm/java/templates.rb +++ /dev/null @@ -1,67 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Realm - module Java - module Templates - - # ANNOTATIONS - PRIMARY_KEY_ANNOTATION = '@PrimaryKey' - INDEXED_ANNOTATION = '@Index' - IGNORED_ANNOTATION = '@Ignore' - GSON_ANNOTATION = "@SerializedName(\"%s\")" - SUPPORT_ANNOTATION = "@android.support.annotation.%s" - - # COMMONS - PACKAGE_TEMPLATE = 'package %s;' - JAVA_FILE_TEMPLATE = '%s.java' - GENERATED_MESSAGE = '/* DO NOT EDIT | Generated by gyro */' - - # IMPORTS - IMPORT_DATE = 'import java.util.Date;' - IMPORT_LIST = 'import java.util.List;' - IMPORT_GSON = 'import com.google.gson.annotations.SerializedName;' - IMPORT_REALM_LIST = 'import io.realm.RealmList;' - IMPORT_REALM_OBJECT = 'import io.realm.RealmObject;' - IMPORT_REALM_IGNORE = 'import io.realm.annotations.Ignore;' - IMPORT_REALM_INDEX = 'import io.realm.annotations.Index;' - IMPORT_REALM_PRIMARY_KEY = 'import io.realm.annotations.PrimaryKey;' - - # ENUM - ENUM_TEMPLATE = 'public enum %s {' - ENUM_JSON_VALUE = "(\"%s\")" - - # CLASS - CLASS_TEMPLATE = 'public class %s extends RealmObject {' - ATTRIBUTE_TEMPLATE = 'private %s %s;' - FINAL_ATTRIBUTE_TEMPLATE = 'private final %s %s;' - REALM_LIST_TEMPLATE = 'RealmList<%s>' - LIST_TEMPLATE = 'List<%s>' - - # CONSTANTS - ATTRIBUTE_CONSTANTS = 'public interface Attributes {' - RELATIONSHIP_CONSTANTS = 'public interface Relationships {' - CONSTANT_TEMPLATE = 'String %s = "%s";' - - # COMMENTS - CLASS_COMMENT_TEMPLATE = "/**\n * %s\n */" - ATTRIBUTE_COMMENT_TEMPLATE = '/** %s */' - - end - end - end -end diff --git a/lib/gyro/realm/objc/converter.rb b/lib/gyro/realm/objc/converter.rb deleted file mode 100644 index e9b8ed7..0000000 --- a/lib/gyro/realm/objc/converter.rb +++ /dev/null @@ -1,63 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Realm - module ObjC - module Converter - - TYPES = { - :integer_16 => 'int', - :integer_32 => 'long', - :integer_64 => 'long long', - :decimal => 'double', - :double => 'double', - :float => 'float', - :string => 'NSString *', - :boolean => 'BOOL', - :date => 'NSDate *', - :binary => 'NSData *' - } - - DEFAULTS = { - :integer_16 => '@(0)', - :integer_32 => '@(0)', - :integer_64 => '@(0)', - :decimal => '@(0.0)', - :double => '@(0.0)', - :float => '@(0.0)', - :string => '@""', - :boolean => '@(NO)', - :date => '[NSDate date]', - :binary => '[NSData new]' - } - - def is_number_type?(type) - [:integer_16, :integer_32, :integer_64, :decimal, :double, :float].include?(type) - end - - def convert_type(type, use_nsnumber = false) - use_nsnumber && is_number_type?(type) ? 'NSNumber *' : TYPES[type] - end - - def convert_default(type) - DEFAULTS[type] - end - - end - end - end -end diff --git a/lib/gyro/realm/objc/enum_generator.rb b/lib/gyro/realm/objc/enum_generator.rb deleted file mode 100644 index 7305555..0000000 --- a/lib/gyro/realm/objc/enum_generator.rb +++ /dev/null @@ -1,81 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Realm - module ObjC - module EnumGenerator - - # INCLUDES ############################################################# - - include Templates - include Converter - - # PUBLIC METHODS ####################################################### - - def generate_enum_file(path, xcdatamodel) - enums = [] - enum_file = String.new - enum_file << GENERATED_MESSAGE + "\n" - enum_file << "\n" + SEPARATOR + "\n\n" - enum_file << PRAGMA_MARK_TYPES + "\n\n" - xcdatamodel.entities.each do |_, entity| - entity.attributes.each do |_, attribute| - if attribute.enum? and !enums.include?(attribute.enum_type) - int_type = convert_type(attribute.type) - enum_type = attribute.enum_type - enum_file << "\n" if enums.length > 0 - enums.push(enum_type) - enum = generate_enum(int_type, enum_type, attribute) - enum_file << enum - end - end - end - if enums.size != 0 - Gyro.write_file_with_name(path, HEADER_TEMPLATE%[ENUM_FILE_NAME], enum_file) - end - end - - private ################################################################ - - def generate_enum(int_type, enum_name, attribute) - enum_string = String.new - enum_string << ENUM_TYPEDEF_TEMPLATE%[int_type, enum_name] + "\n" - enum_values = Array.new - enum_values += %W(#{enum_name}None) if attribute.optional? - enum_values += attribute.enum_values - if enum_values.length != 0 - # First one - value = enum_values[0] - enum_string << ' ' + value + ' = 0,' + "\n" - # Others - (1..enum_values.length - 2).each { |i| - value = enum_values[i] - enum_string << ' ' + value + ',' + "\n" - } - # Last one if at least 2 values - if enum_values.length > 1 - value = enum_values.last - enum_string << ' ' + value + "\n" - end - end - enum_string << '};' + "\n" - end - - end - end - end -end diff --git a/lib/gyro/realm/objc/generator.rb b/lib/gyro/realm/objc/generator.rb deleted file mode 100644 index d11698b..0000000 --- a/lib/gyro/realm/objc/generator.rb +++ /dev/null @@ -1,370 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -require 'gyro/xcdatamodel/parser' -require 'gyro/realm/objc/templates' -require 'gyro/realm/objc/converter' -require 'gyro/realm/objc/protocol_generator' -require 'gyro/realm/objc/enum_generator' -require 'gyro/realm/objc/json_category_generator' - -module Gyro - module Realm - module ObjC - - class Generator - - # INCLUDES ############################################################# - - include Gyro::XCDataModel::Parser - include Converter - include Templates - include ProtocolGenerator - include EnumGenerator - include JSONCategoryGenerator - - # PUBLIC METHODS ####################################################### - - def initialize(path, xcdatamodel, json = false, framework = false, use_nsnumber = false) - generate_class_files(path, xcdatamodel, use_nsnumber) - generate_protocol_file(path, xcdatamodel) - generate_enum_file(path, xcdatamodel) - generate_objc_categories(path, xcdatamodel, framework) if json - end - - private ################################################################ - - def generate_class_files(path, xcdatamodel, use_nsnumber) - puts "\n" - Gyro::Log::title('Objc Realm') - xcdatamodel.entities.each do |_, entity| - unless entity.abstract? - Gyro::Log::success("Generating entity #{entity.name}...") - generate_class(path, entity, use_nsnumber) - end - end - end - - def generate_class(path, entity, use_nsnumber) - header_file = generate_header_file(entity, use_nsnumber) - source_file = generate_source_file(entity, use_nsnumber) - Gyro.write_file_with_name(path, HEADER_TEMPLATE%[entity.name], header_file) - Gyro.write_file_with_name(path, SOURCE_TEMPLATE%[entity.name], source_file) - end - - def generate_header_file(entity, use_nsnumber) - header_file = String.new - header_file << GENERATED_MESSAGE + "\n" - header_file << "\n" + SEPARATOR + "\n\n" - header_file << PRAGMA_MARK_IMPORTS + "\n\n" - header_file << IMPORT_REALM + "\n" - header_file << IMPORT_HEADER%[ENUM_FILE_NAME] + "\n" if require_enum_import(entity) - header_file << generate_import_protocols(entity) - header_file << generate_class_types(entity) - header_file << generate_header_constants(entity) - header_file << "\n" + SEPARATOR + "\n\n" - header_file << PRAGMA_MARK_INTERFACE + "\n\n" - header_file << CLASS_COMMENT_TEMPLATE%[entity.comment] + "\n" unless entity.comment.empty? - header_file << INTERFACE_TEMPLATE%[entity.name] + "\n" - header_file << generate_properties(entity, use_nsnumber) - header_file << "\n" << END_CODE + "\n" - end - - def generate_properties(entity, use_nsnumber) - header_file = String.new - header_file << "\n" + PRAGMA_MARK_PROPERTIES + "\n\n" - entity.attributes.each do |_, attribute| - header_file << PROPERTY_COMMENT_TEMPLATE%[attribute.comment] + "\n" unless attribute.comment.empty? - name = attribute.name - use_nsnumber_wrapper = use_nsnumber && require_nsnumber_wrapper(attribute) - type = attribute.enum? ? attribute.enum_type : convert_type(attribute.type, use_nsnumber_wrapper) - if type.nil? - Gyro::Log::error("The property #{name} of entity #{entity.name} has an Undefined type.") - type = 'id' - end - type = '(readonly) ' + type unless attribute.realm_read_only.empty? - header_file << SIMPLE_PROPERTY_TEMPLATE%[type, type.end_with?('*') ? name : ' ' + name] + "\n" - if use_nsnumber_wrapper - num_type = convert_type(attribute.type) - header_file << NUMBER_ACCESSOR_DECL_TEMPLATES%[num_type, name, name.capitalize_first_letter, num_type] - end - end - entity.relationships.each do |_, relationship| - is_list = relationship.type == :to_many - if relationship.inverse? - type = '(readonly) ' + (is_list ? 'NSArray' : relationship.inverse_type) - name = relationship.name.delete_inverse_suffix - else - if relationship.destination.empty? - type = is_list ? REALM_LIST_TEMPLATE%[relationship.inverse_type] : relationship.inverse_type - else - type = LIST_TEMPLATE%[convert_type(relationship.destination.downcase.to_sym)] - end - name = relationship.name - end - header_file << OBJECT_PROPERTY_TEMPLATE%[type, name] + "\n" - end - header_file - end - - def require_nsnumber_wrapper(attribute) - !attribute.enum? && attribute.realm_read_only.empty? && is_number_type?(attribute.type) - end - - def require_enum_import(entity) - entity.attributes.each do |_, attribute| - if attribute.enum? - return true - end - end - false - end - - def generate_import_protocols(entity) - entity.has_list_attributes?(true) ? IMPORT_HEADER%[PROTOCOL_FILE_NAME] + "\n" : '' - end - - def generate_class_types(entity) - class_types = String.new - entity.relationships.each do |_, relationship| - class_types << CLASS_TEMPLATE%[relationship.inverse_type] + "\n" if relationship.inverse_type != entity.name && relationship.destination.empty? - end - class_types.empty? ? class_types : "\n" + PRAGMA_MARK_TYPES + "\n\n" + class_types - end - - def generate_header_constants(entity) - constants = String.new - unless entity.attributes.empty? - name = CONSTANT_ATTRIBUTES_NAME%[entity.name] - constants << CONSTANT_HEADER_ATTRIBUTES%[name, name] + "\n" - entity.attributes.each do |_, attribute| - constants << ' ' + CONSTANT_HEADER_ITEM%[attribute.name] + "\n" - end - constants << "} #{name};\n" - end - if entity.has_no_inverse_relationship? - constants << "\n" unless constants.empty? - name = CONSTANT_RELATIONSHIPS_NAME%[entity.name] - constants << CONSTANT_HEADER_RELATIONSHIPS%[name] + "\n" - entity.relationships.each do |_, relationship| - constants << ' ' + CONSTANT_HEADER_ITEM%[relationship.name] + "\n" unless relationship.inverse? - end - constants << "} #{name};\n" - end - constants.empty? ? constants : "\n" + PRAGMA_MARK_CONSTANTS + "\n\n"+ constants - end - - def generate_source_file(entity, use_nsnumber) - source_file = String.new - source_file << GENERATED_MESSAGE + "\n" - source_file << "\n" + SEPARATOR + "\n\n" - source_file << PRAGMA_MARK_IMPORTS + "\n\n" - source_file << IMPORT_HEADER%[entity.name] + "\n" - source_file << generate_source_constants(entity) - source_file << "\n" + SEPARATOR + "\n\n" - source_file << PRAGMA_MARK_IMPLEMENTATION + "\n\n" - source_file << IMPLEMENTATION_TEMPLATE%[entity.name] + "\n" - source_file << generate_numbers_accessors(entity) if use_nsnumber - if require_overriding(entity) - source_file << "\n" + PRAGMA_MARK_SUPER + "\n" - source_file << generate_primary_key(entity) - source_file << generate_required_properties(entity) - source_file << generate_default_values(entity) - source_file << generate_ignored_properties(entity) - source_file << generate_read_only_properties(entity, use_nsnumber) - source_file << generate_inverse_properties(entity) - end - source_file << "\n" << END_CODE + "\n" - end - - def generate_source_constants(entity) - constants = String.new - unless entity.attributes.empty? - name = CONSTANT_ATTRIBUTES_NAME%[entity.name] - constants << CONSTANT_SOURCE_ATTRIBUTES%[name, name] + "\n" - entity.attributes.each_with_index do |(_, attribute), idx| - constants << ',' + "\n" unless idx == 0 - constants << ' ' + CONSTANT_SOURCE_ITEM%[attribute.name, attribute.name] - constants << "\n" if idx == entity.attributes.length - 1 - end - constants << '};' + "\n" - end - if entity.has_no_inverse_relationship? - constants << "\n" unless constants.empty? - name = CONSTANT_RELATIONSHIPS_NAME%[entity.name] - constants << CONSTANT_SOURCE_RELATIONSHIPS%[name, name] + "\n" - has_first = false - entity.relationships.each_with_index do |(_, relationship), idx| - unless relationship.inverse? - constants << ',' + "\n" if has_first - constants << ' ' + CONSTANT_SOURCE_ITEM%[relationship.name, relationship.name] - has_first = true - end - constants << "\n" if idx == entity.relationships.length - 1 - end - constants << '};' + "\n" - end - constants.empty? ? constants : "\n" + PRAGMA_MARK_CONSTANTS + "\n\n" + constants - end - - def generate_numbers_accessors(entity) - number_accessors = String.new - entity.attributes.each do |_, attribute| - if require_nsnumber_wrapper(attribute) - type = convert_type(attribute.type) - name = attribute.name - selector = type.gsub(/ /, '') + 'Value' - number_accessors << NUMBER_ACCESSOR_SOURCE_TEMPLATES%[type, name, name, selector, name.capitalize_first_letter, type, name] + "\n" - end - end - number_accessors.empty? ? "" : "\n" + PRAGMA_MARK_NUMBER_ACCESSORS + "\n\n" + number_accessors - end - - def require_overriding(entity) - if entity.has_primary_key? or entity.attributes.count > 0 - return true - end - false - end - - def generate_primary_key(entity) - primary_key = String.new - if entity.has_primary_key? - primary_key << "\n" + '+ (NSString *)primaryKey' + "\n" - primary_key << '{' + "\n" - primary_key << ' ' + "return @\"" + entity.identity_attribute + "\";" + "\n" - primary_key << '}' + "\n" - end - primary_key - end - - def generate_required_properties(entity) - required_properties = String.new - if entity.has_required? - required_properties << "\n" + '// Specify required properties' + "\n" - required_properties << '+ (NSArray *)requiredProperties' + "\n" - required_properties << '{' + "\n" - required_properties << ' ' + 'return @[' - entity.attributes.each do |_, attribute| - required_properties << ARRAY_TEMPLATE%[attribute.name.add_quotes] if entity.is_required?(attribute) - end - required_properties = required_properties[0..required_properties.length - 3] # delete last coma - required_properties << '];' + "\n" - required_properties << '}' + "\n" - end - required_properties - end - - def generate_default_values(entity) - default_values = String.new - if entity.has_required? - default_values << "\n" + '// Specify default values for required properties' + "\n" - default_values << '+ (NSDictionary *)defaultPropertyValues' + "\n" - default_values << '{' + "\n" - default_values << ' ' + 'return @{' - entity.attributes.each do |_, attribute| - if entity.is_required?(attribute) - default_value = convert_default(attribute.type) - if entity.has_default_value?(attribute) && !attribute.default.empty? - default_value = attribute.type == :string ? "@\"#{attribute.default})\"" : "@(#{attribute.default})" - end - default_values << DICTIONARY_DEFAULT%[attribute.name.add_quotes, default_value] + ' ' - end - end - default_values = default_values[0..default_values.length - 3] # delete last coma - default_values << '};' + "\n" - default_values << '}' + "\n" - end - default_values - end - - def generate_ignored_properties(entity) - ignored_properties = String.new - if entity.has_ignored? - ignored_properties << "\n" + "// Specify properties to ignore (Realm won't persist these)" + "\n" - ignored_properties << '+ (NSArray *)ignoredProperties' + "\n" - ignored_properties << '{' + "\n" - ignored_properties << ' ' + 'return @[' - entity.attributes.each do |_, attribute| - ignored_properties << ARRAY_TEMPLATE%[attribute.name.add_quotes] if attribute.realm_ignored? - end - entity.relationships.each do |_, relationship| - ignored_properties << ARRAY_TEMPLATE%[relationship.name.add_quotes] if relationship.realm_ignored? - end - ignored_properties = ignored_properties[0..ignored_properties.length - 3] # delete last coma - ignored_properties << '];' + "\n" - ignored_properties << '}' + "\n" - end - ignored_properties - end - - def generate_read_only_properties(entity, use_nsnumber) - read_only_properties = String.new - entity.attributes.each do |_, attribute| - unless attribute.realm_read_only.empty? - type = attribute.enum? ? attribute.enum_type : convert_type(attribute.type, use_nsnumber) - read_only_properties << "\n" + READ_ONLY_DEF_TEMPLATE%[type, attribute.name] + "\n" - read_only_properties << '{' + "\n" - read_only_properties << ' ' + attribute.realm_read_only + "\n" - read_only_properties << '}' + "\n" - end - end - read_only_properties - end - - def generate_inverse_properties(entity) - inverse_properties = String.new - entity.relationships.each do |_, relationship| - if relationship.inverse? - if relationship.type == :to_many - definition = INVERSE_DEF_TEMPLATE%['NSArray', relationship.name.delete_inverse_suffix] - value = INVERSE_MANY_TEMPLATE%[relationship.inverse_type, relationship.inverse_name] - else - definition = INVERSE_DEF_TEMPLATE%[relationship.inverse_type, relationship.name.delete_inverse_suffix] - value = INVERSE_ONE_TEMPLATE%[relationship.inverse_type, relationship.inverse_name] - end - inverse_properties << "\n" + definition + "\n" - inverse_properties << '{' + "\n" - inverse_properties << ' ' + value + "\n" - inverse_properties << '}' + "\n" - end - end - inverse_properties - end - - def generate_indexed_properties(entity) - indexed_properties = String.new - if entity.has_indexed_attributes? - indexed_properties << "\n" + '// Specify properties to index' + "\n" - indexed_properties << '+ (NSArray *)ignoredProperties' + "\n" - indexed_properties << '{' + "\n" - indexed_properties << ' ' + 'return @[' - entity.attributes.each do |_, attribute| - if attribute.indexed - indexed_properties << ARRAY_TEMPLATE%[attribute.name.add_quotes] - end - end - indexed_properties = indexed_properties[0..indexed_properties.length - 3] # delete last coma - indexed_properties << '];' + "\n" - indexed_properties << '}' + "\n" - end - indexed_properties - end - - end - end - end -end diff --git a/lib/gyro/realm/objc/json_category_generator.rb b/lib/gyro/realm/objc/json_category_generator.rb deleted file mode 100644 index f784954..0000000 --- a/lib/gyro/realm/objc/json_category_generator.rb +++ /dev/null @@ -1,168 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Realm - module ObjC - module JSONCategoryGenerator - - # INCLUDES ############################################################# - - include Templates - - # PUBLIC METHODS ####################################################### - - def generate_objc_categories(path, xcdatamodel, framework = false) - json_path = File.join(path, 'JSON') - Dir.mkdir(json_path) unless Dir.exists?(json_path) - xcdatamodel.entities.each do |_, entity| - generate_json_category_file(json_path, entity, framework) - end - end - - private ################################################################# - - def generate_json_category_file(path, entity, framework) - if !entity.attributes.empty? || !entity.relationships.empty? - source_file = generate_source_category_file(entity) - header_file = generate_header_category_file(entity, framework) - file_name = JSON_CATEGORY_NAME%[entity.name] - Gyro.write_file_with_name(path, HEADER_TEMPLATE%[file_name], header_file) unless header_file.empty? - Gyro.write_file_with_name(path, SOURCE_TEMPLATE%[file_name], source_file) unless source_file.empty? - end - end - - def generate_header_category_file(entity, framework) - header_file = String.new - header_file << GENERATED_MESSAGE + "\n" - header_file << "\n" + SEPARATOR + "\n\n" - header_file << PRAGMA_MARK_IMPORTS + "\n\n" - header_file << (framework ? IMPORT_REALM_JSON_FRAMEWORK : IMPORT_REALM_JSON_LIBRARY) + "\n" - header_file << IMPORT_HEADER%[entity.name] + "\n" - header_file << "\n" + SEPARATOR + "\n\n" - header_file << PRAGMA_MARK_INTERFACE + "\n\n" - header_file << JSON_CATEGORY_INTERFACE%[entity.name] + "\n\n" - header_file << END_CODE + "\n" - header_file - end - - def generate_source_category_file(entity) - source_file = String.new - source_file << GENERATED_MESSAGE + "\n" - source_file << "\n" + SEPARATOR + "\n\n" - source_file << PRAGMA_MARK_IMPORTS + "\n\n" - source_file << IMPORT_HEADER%[JSON_CATEGORY_NAME%[entity.name]] + "\n" - source_file << IMPORT_HEADER%[ENUM_FILE_NAME] + "\n" if entity.has_enum_attributes? - entity.transformers.each do |name| - source_file << IMPORT_HEADER%[name]+"\n" - end - source_file << "\n" + SEPARATOR + "\n\n" - source_file << PRAGMA_MARK_IMPLEMENTATION + "\n\n" - source_file << JSON_CATEGORY_IMPLEMENTATION%[entity.name] + "\n\n" - source_file << generate_mapping(entity) - source_file << "\n" + generate_json_transformers(entity) if entity.need_transformer? - source_file << "\n" + END_CODE + "\n" - source_file - end - - def generate_mapping(entity) - inbound_mapping_string = '+ (NSDictionary *)JSONInboundMappingDictionary' + "\n" - inbound_mapping_string << '{' + "\n" - inbound_mapping_string << ' ' + 'return @{' + "\n" - outbound_mapping_string = '+ (NSDictionary *)JSONOutboundMappingDictionary' + "\n" - outbound_mapping_string << '{' + "\n" - outbound_mapping_string << ' '+ 'return @{' + "\n" - - entity.attributes.each do |_, attribute| - json_value = attribute.json_key_path.empty? ? attribute.name.add_quotes : attribute.json_key_path.add_quotes - inbound_mapping_string << ' ' + DICTIONARY_JSON%[json_value, attribute.name.add_quotes] + "\n" - outbound_mapping_string << ' ' + DICTIONARY_JSON%[attribute.name.add_quotes, json_value] + "\n" - end - - entity.relationships.each do |_, relationship| - json_value = relationship.json_key_path.empty? ? relationship.name.add_quotes : relationship.json_key_path.add_quotes - inbound_mapping_string << ' ' + DICTIONARY_JSON%[json_value, relationship.name.add_quotes] + "\n" - outbound_mapping_string << ' ' + DICTIONARY_JSON%[relationship.name.add_quotes, json_value] + "\n" - end - - #delete last coma - inbound_mapping_string = inbound_mapping_string[0..inbound_mapping_string.length - 3] + "\n" - inbound_mapping_string << ' ' +'};' + "\n" - inbound_mapping_string << '}' + "\n\n" - outbound_mapping_string = outbound_mapping_string[0..outbound_mapping_string.length - 3] + "\n" - outbound_mapping_string << ' ' + '};' + "\n" - outbound_mapping_string << '}' + "\n" - inbound_mapping_string + outbound_mapping_string - end - - def generate_json_transformers(entity) - json_transformer_string = String.new - first_transformer = true - entity.attributes.each do |(_, attribute)| - if attribute.need_transformer? - json_transformer_string << "\n" unless first_transformer - first_transformer = false - json_transformer_string << JSON_TRANSFORMER_DEF%[attribute.name] + "\n" - json_transformer_string << '{'+ "\n" - if !attribute.enum_type.empty? or attribute.type == :boolean # Enum | Boolean - json_transformer_string << ' ' + 'return [MCJSONValueTransformer valueTransformerWithMappingDictionary:@{' + "\n" - if attribute.type == :boolean - json_values = TRANSFORMER_BOOL_JSON - model_values = TRANSFORMER_BOOL_MODEL - else - if attribute.json_values.empty? - Gyro::Error::raise("The attribute \"%s\" from \"%s\" is enum without JSONValues - please fix it"%[attribute.name, attribute.entity_name]) - end - json_values = TRANSFORMER_ENUM_JSON + attribute.json_values.map { |enum| '@' + enum.add_quotes } - enums = attribute.enum_values - if attribute.optional? - default = attribute.enum_type + 'None' - else - default = enums[attribute.default.to_i] - end - model_values = [default, default, default] + enums - model_values = [default, default, default, default] + enums - end - json_transformer_string << format_json_transformers(json_values, model_values) - - # delete last coma - json_transformer_string = json_transformer_string[0..json_transformer_string.length - 3] + "\n" - json_transformer_string << ' ' + '}];' + "\n" - else # custom transformer, or a default one - transformer = attribute.transformer - transformer = 'ISO8601DateTransform' if transformer.empty? && attribute.type == :date # default one for dates if none provided - json_transformer_string << ' ' + TRANSFORMER%[transformer] + "\n" unless transformer.empty? - end - json_transformer_string << '}' + "\n" - end - end - json_transformer_string - end - - def format_json_transformers(json_values, model_values) - json_transformer_string = String.new - (0..model_values.length - 1).each { |enum| - json_value = json_values[enum] - enum_value = model_values[enum].add_parentheses - json_transformer_string << ' ' + DICTIONARY_JSON_CATEGORY%[json_value, enum_value] + "\n" - } - json_transformer_string - end - - end - end - end -end diff --git a/lib/gyro/realm/objc/protocol_generator.rb b/lib/gyro/realm/objc/protocol_generator.rb deleted file mode 100644 index 19aa884..0000000 --- a/lib/gyro/realm/objc/protocol_generator.rb +++ /dev/null @@ -1,54 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Realm - module ObjC - module ProtocolGenerator - - # INCLUDES ############################################################# - - include Templates - include Converter - - # PUBLIC METHODS ####################################################### - - def generate_protocol_file(path, xcdatamodel) - content = String.new - xcdatamodel.entities.each do |_, entity| - unless entity.abstract? - if entity.used_as_list_by_other?(xcdatamodel.entities) - content << protocol_file_template if content.empty? - content << REALM_LIST_TYPE_TEMPLATE%[entity.name, entity.name] + "\n" - end - end - end - Gyro.write_file_with_name(path, HEADER_TEMPLATE%[PROTOCOL_FILE_NAME], content) unless content.empty? - end - - private ################################################################ - - def protocol_file_template - content = String.new - content << GENERATED_MESSAGE + "\n" - content << "\n" + SEPARATOR + "\n\n" - content << PRAGMA_MARK_PROTOCOLS + "\n\n" - end - - end - end - end -end diff --git a/lib/gyro/realm/objc/templates.rb b/lib/gyro/realm/objc/templates.rb deleted file mode 100644 index 3601087..0000000 --- a/lib/gyro/realm/objc/templates.rb +++ /dev/null @@ -1,100 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Realm - module ObjC - module Templates - - # IMPORTS - IMPORT_REALM = '#import ' - IMPORT_HEADER = '#import "%s.h"' - IMPORT_REALM_JSON_LIBRARY = '#import ' - IMPORT_REALM_JSON_FRAMEWORK = '#import "RLMObject+JSON.h"' - - - # PRAGMA - PRAGMA_MARK_IMPORTS = '#pragma mark - Imports' - PRAGMA_MARK_TYPES = '#pragma mark - Types' - PRAGMA_MARK_CONSTANTS = '#pragma mark - Defines & Constants' - PRAGMA_MARK_INTERFACE = '#pragma mark - Interface' - PRAGMA_MARK_PROPERTIES = '#pragma mark - Properties' - PRAGMA_MARK_PROTOCOLS = '#pragma mark - Protocols' - PRAGMA_MARK_IMPLEMENTATION = '#pragma mark - Implementation' - PRAGMA_MARK_NUMBER_ACCESSORS = '#pragma mark - NSNumber Convenience Accessors' - PRAGMA_MARK_SUPER = '#pragma mark - Superclass Overrides' - - # COMMONS - GENERATED_MESSAGE = '// DO NOT EDIT | Generated by gyro' - END_CODE = '@end' - SEPARATOR = '////////////////////////////////////////////////////////////////////////////////' - DICTIONARY_JSON = '@%s : @%s,' - DICTIONARY_DEFAULT = '@%s : %s,' - DICTIONARY_JSON_CATEGORY = '%s : @%s,' - - # HEADER - HEADER_TEMPLATE = '%s.h' - NUMBER_TRANSFORMER_FILE_NAME = 'NFNumberTransformer' - CLASS_COMMENT_TEMPLATE = "/**\n * %s\n */" - CLASS_TEMPLATE = '@class %s;' - INTERFACE_TEMPLATE = '@interface %s : RLMObject' - PROPERTY_COMMENT_TEMPLATE = '/** %s */' - SIMPLE_PROPERTY_TEMPLATE = '@property %s%s;' - OBJECT_PROPERTY_TEMPLATE = '@property %s *%s;' - NUMBER_ACCESSOR_DECL_TEMPLATES = "-(%s)%sValue;\n-(void)set%sValue:(%s)value;\n" - LIST_TEMPLATE = 'NSArray<%s>' - REALM_LIST_TYPE_TEMPLATE = "// This protocol enables typed collections. i.e.: RLMArray<%s>\nRLM_ARRAY_TYPE(%s)" - REALM_LIST_TEMPLATE = 'RLMArray<%s>' - - # COMMONS - CONSTANT_ATTRIBUTES_NAME = '%sAttributes' - CONSTANT_RELATIONSHIPS_NAME = '%sRelationships' - CONSTANT_HEADER_ATTRIBUTES = 'extern const struct %s {' - CONSTANT_HEADER_RELATIONSHIPS = 'extern const struct %s {' - CONSTANT_HEADER_ITEM = '__unsafe_unretained NSString *%s;' - CONSTANT_SOURCE_ATTRIBUTES = 'const struct %s %s = {' - CONSTANT_SOURCE_RELATIONSHIPS = 'const struct %s %s = {' - CONSTANT_SOURCE_ITEM = '.%s = @"%s"' - - # ENUM - ENUM_TYPEDEF_TEMPLATE = 'typedef NS_ENUM(%s, %s) {' - ENUM_FILE_NAME = 'RLMTypes' - PROTOCOL_FILE_NAME = 'RLMProtocols' - - # SOURCE - SOURCE_TEMPLATE = '%s.m' - IMPLEMENTATION_TEMPLATE = '@implementation %s' - ARRAY_TEMPLATE ='@%s, ' - READ_ONLY_DEF_TEMPLATE = '- (%s)%s' - NUMBER_ACCESSOR_SOURCE_TEMPLATES = "-(%s)%sValue\n{\n return [self.%s %s];\n}\n-(void)set%sValue:(%s)value\n{\n self.%s = @(value);\n}" - INVERSE_DEF_TEMPLATE = '- (%s *)%s' - INVERSE_MANY_TEMPLATE = 'return [self linkingObjectsOfClass:@"%s" forProperty:@"%s"];' - INVERSE_ONE_TEMPLATE = 'return [[self linkingObjectsOfClass:@"%s" forProperty:@"%s"] objectAtIndex:0];' - - # JSON_CATEGORY - JSON_CATEGORY_NAME = '%s+JSON' - JSON_TRANSFORMER_DEF = '+ (NSValueTransformer *)%sJSONTransformer' - JSON_CATEGORY_IMPLEMENTATION = '@implementation %s (JSON)' - JSON_CATEGORY_INTERFACE = '@interface %s (JSON)' - TRANSFORMER_BOOL_JSON = ['@"null"', '[NSNull null]', '@""', '@"false"', '@"true"', '@(NO)', '@(YES)'] - TRANSFORMER_BOOL_MODEL = %w(NO NO NO NO YES NO YES) - TRANSFORMER_ENUM_JSON = ['@"null"', '[NSNull null]', '@""', '@""'] - TRANSFORMER = 'return [[%s alloc] init];' - - end - end - end -end diff --git a/lib/gyro/realm/swift/converter.rb b/lib/gyro/realm/swift/converter.rb deleted file mode 100644 index b7fd05f..0000000 --- a/lib/gyro/realm/swift/converter.rb +++ /dev/null @@ -1,74 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Realm - module Swift - module Converter - - TYPES = { - :integer_16 => 'Int16', - :integer_32 => 'Int32', - :integer_64 => 'Int64', - :decimal => 'Double', - :double => 'Double', - :float => 'Float', - :string => 'String', - :boolean => 'Bool', - :date => 'NSDate', - :binary => 'NSData' - } - - DEFAULTS = { - :integer_16 => '0', - :integer_32 => '0', - :integer_64 => '0', - :decimal => '0.0', - :double => '0.0', - :float => '0.0', - :string => '""', - :boolean => 'false', - :date => 'NSDate()', - :binary => 'NSData()' - } - - def convert_type(type) - TYPES[type] - end - - def convert_default(type, value = nil) - if value.nil? - return DEFAULTS[type] - end - # Do some conversions for some special types - case [type, value] - when [:boolean, 'YES'] - return 'true' - when [:boolean, 'NO'] - return 'false' - else - return value - end - end - - def is_number?(type) - type != :string && type != :date && type != :binary - end - - end - end - end -end diff --git a/lib/gyro/realm/swift/enum_generator.rb b/lib/gyro/realm/swift/enum_generator.rb deleted file mode 100644 index faf825d..0000000 --- a/lib/gyro/realm/swift/enum_generator.rb +++ /dev/null @@ -1,69 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Realm - module Swift - module EnumGenerator - - # INCLUDES ############################################################# - - include Templates - - # PUBLIC METHODS ####################################################### - - def generate_enums(path, attributes) - enums = Array.new - attributes.each do |_, attribute| - if attribute.enum? and !enums.include?(attribute.enum_type) - enum_type = attribute.enum_type.delete_objc_prefix - enums.push(enum_type) - generate_enum(path, enum_type, attribute.enum_values, attribute.json_values) - end - end - end - - private ################################################################ - - def generate_enum(path, enum_name, enum_values, raw_values) - enum_file = String.new - enum_file << GENERATED_MESSAGE + "\n\n" - enum_file << ENUM_STRING_DEF_TEMPLATE%[enum_name] + "\n" - raw_values = raw_values(enum_values, raw_values) - if !enum_values.empty? and raw_values.length == enum_values.length - (0..enum_values.length - 1).each { |idx| - enum_value = enum_values[idx].delete_objc_prefix - raw_value = raw_values[idx] - enum_file << ' ' + ENUM_STRING_CASE_TEMPLATE%[enum_value, raw_value] + "\n" - } - enum_file << '}' + "\n" - Gyro.write_file_with_name(path, SWIFT_FILE_TEMPLATE%[enum_name], enum_file) - end - end - - def raw_values(enum_values, raw_values) - if raw_values.empty? - raw_values = enum_values.map { |value| - value.delete_objc_prefix.underscore - } - end - raw_values - end - - end - end - end -end diff --git a/lib/gyro/realm/swift/generator.rb b/lib/gyro/realm/swift/generator.rb deleted file mode 100644 index 918a952..0000000 --- a/lib/gyro/realm/swift/generator.rb +++ /dev/null @@ -1,262 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -require 'gyro/xcdatamodel/parser' -require 'gyro/realm/swift/templates' -require 'gyro/realm/swift/converter' -require 'gyro/realm/swift/enum_generator' -require 'gyro/realm/swift/object_mapper_generator' - -module Gyro - module Realm - module Swift - - class Generator - - # INCLUDES ############################################################# - - include Gyro::XCDataModel::Parser - include Converter - include EnumGenerator - include Templates - include ObjectMapperGenerator - - # PUBLIC METHODS ####################################################### - - def initialize(path, xcdatamodel, json = false) - puts "\n" - Gyro::Log::title('Swift Realm') - xcdatamodel.entities.each do |_, entity| - unless entity.abstract? - Gyro::Log::success("Generating entity #{entity.name}...") - generate_class(path, entity, json) - generate_object_mapper_categories(path, xcdatamodel) if json - end - end - end - - private ################################################################ - - def generate_class(path, entity, json) - class_file = String.new - entity.name = entity.name.delete_objc_prefix - class_file << generate_header(entity) - class_file << generate_attributes(entity.attributes, entity.relationships, json) - class_file << generate_inverse_properties(entity) - class_file << generate_primary_key(entity) - class_file << generate_indexed_properties(entity) - class_file << generate_ignored_properties(entity) - class_file << '}' + "\n" - Gyro.write_file_with_name(path, SWIFT_FILE_TEMPLATE%[entity.name], class_file) - generate_enums(path, entity.attributes) - end - - def generate_header(entity) - class_file = String.new - class_file << GENERATED_MESSAGE + "\n\n" - class_file << IMPORT_REALM + "\n\n" - class_file << CLASS_COMMENT_TEMPLATE%[entity.comment] + "\n" unless entity.comment.empty? - class_file << CLASS_TEMPLATE%[entity.name] + "\n\n" - class_file << generate_constants(entity) - end - - def generate_constants(entity) - attribute_constants = String.new - unless entity.attributes.empty? - attribute_constants << ' ' + ENUM_STRING_DEF_TEMPLATE%['Attributes'] + "\n" - entity.attributes.each do |_, attribute| - unless attribute.realm_ignored? or attribute.read_only? - attribute_constants << ' ' + ATTRIBUTE_COMMENT_TEMPLATE%[attribute.comment] + "\n" unless attribute.comment.empty? - attribute_constants << ' ' + ENUM_STRING_CASE_TEMPLATE%[attribute.name.capitalize_first_letter, attribute.name] + "\n" - end - end - attribute_constants << ' ' + '}'+ "\n\n" - end - relationship_constants = String.new - if not entity.relationships.empty? and not entity.has_only_inverse? - relationship_constants << ' ' + ENUM_STRING_DEF_TEMPLATE%['Relationships'] + "\n" - entity.relationships.each do |_, relationship| - relationship_constants << ' ' + ENUM_STRING_CASE_TEMPLATE%[relationship.name.capitalize_first_letter, relationship.name] + "\n" if not relationship.inverse? - end - relationship_constants << ' ' + '}'+ "\n\n" - end - attribute_constants + relationship_constants - end - - def generate_attributes(attributes, relationships, json) - # "NORMAL" ATTRIBUTES - attributes_string = write_attributes(attributes, json) - # "RELATIONSHIP" ATTRIBUTES - relationships.each do |_, relationship| - unless relationship.inverse? - is_list = relationship.type == :to_many - name = relationship.name - type = relationship.inverse_type.delete_objc_prefix - if is_list - if json - attributes_string << ' ' + PROPERTY_LIST_VAR_TEMPLATE%[name, type] + "\n" - else - attributes_string << ' ' + PROPERTY_LIST_TEMPLATE%[name, type] + "\n" - end - else - attributes_string << ' ' + PROPERTY_OBJECT_TEMPLATE%[name, type] + "\n" - end - end - end - attributes_string + "\n" - end - - def write_attributes(attributes, json) - attributes_string = String.new - attributes.each_with_index do |(_, attribute)| - unless attribute.read_only? - if attribute.enum? - attributes_string << write_enum_attribute(attribute, json) - else - if attribute.optional? - attributes_string << write_optional_attribute(attribute, json) + "\n" - else - default_value = convert_default(attribute.type, attribute.has_default? ? attribute.default : nil) - attributes_string << ' ' + PROPERTY_DEFAULT_TEMPLATE%[attribute.name, convert_type(attribute.type), default_value] + "\n" - end - end - end - end - attributes_string - end - - def write_optional_attribute(attribute, json) - optional_string = String.new - type = convert_type(attribute.type) - if attribute.is_number? or attribute.is_bool? - if json - optional_string << ' ' + PROPERTY_OPTIONAL_NUMBER_VAR_TEMPLATE%[attribute.name, type] - else - optional_string << ' ' + PROPERTY_OPTIONAL_NUMBER_TEMPLATE%[attribute.name, type] - end - else - optional_string << ' ' + PROPERTY_OPTIONAL_NON_NUMBER_TEMPLATE%[attribute.name, type] - end - optional_string - end - - def write_enum_attribute(attribute, json) - enum_string = String.new - if attribute.optional? - enum_string << ' ' + PROPERTY_OPTIONAL_ENUM_TEMPLATE%[attribute.name] + "\n" - else - enum_string << ' ' + PROPERTY_ENUM_TEMPLATE%[attribute.name] + "\n" - end - enum_type = attribute.enum_type.delete_objc_prefix - enum_name = attribute.name + 'Enum' - - enum_string << ' ' + PROPERTY_OPTIONAL_COMPUTED_TEMPLATE%[enum_name, enum_type] + "\n" - enum_string << ' ' + 'get {' + "\n" - if attribute.optional? - enum_string << ' ' + "guard let #{attribute.name} = #{attribute.name},\n" - enum_string << ' ' + " let enumValue = #{enum_type}(rawValue: #{attribute.name})\n" - enum_string << ' ' + " else { return nil }" + "\n" - else - enum_string << ' ' + "guard let enumValue = #{enum_type}(rawValue: #{attribute.name}) else { return nil }" + "\n" - end - enum_string << ' ' + "return enumValue" + "\n" - enum_string << ' ' + '}' + "\n" - - if attribute.optional? - enum_string << ' ' + "set { #{attribute.name} = newValue?.rawValue ?? nil }" + "\n" - else - enum_string << ' ' + "set { #{attribute.name} = newValue?.rawValue ?? \"\" }" + "\n" - end - enum_string << ' ' + '}' + "\n\n" - end - - def generate_primary_key(entity) - primary_key = String.new - if entity.has_primary_key? - primary_key << ' ' + 'override static func primaryKey() -> String? {' + "\n" - primary_key << ' ' + "return #{entity.identity_attribute.add_quotes}" + "\n" - primary_key << ' ' + '}' + "\n\n" - end - primary_key - end - - def generate_ignored_properties(entity) - ignored_properties = String.new - if entity.has_ignored? - ignored_properties << ' ' + "// Specify properties to ignore (Realm won't persist these)" + "\n" - ignored_properties << ' ' +'override static func ignoredProperties() -> [String] {' + "\n" - ignored_properties << ' ' + 'return [' - entity.attributes.each do |_, attribute| - ignored_properties << ARRAY_TEMPLATE%[attribute.name.add_quotes] if attribute.realm_ignored? - end - entity.relationships.each do |_, relationship| - ignored_properties << ARRAY_TEMPLATE%[relationship.name.add_quotes] if relationship.realm_ignored? - end - ignored_properties = ignored_properties[0..ignored_properties.length - 3] # delete last coma - ignored_properties << ']' + "\n" - ignored_properties << ' ' + '}' + "\n\n" - end - ignored_properties - end - - def generate_inverse_properties(entity) - inverse_properties = [] - entity.relationships.each do |_, relationship| - if relationship.inverse? - if relationship.type == :to_many - inverse_properties << PROPERTY_INVERSE_MANY_TEMPLATE%[ - relationship.name.delete_inverse_suffix, - relationship.inverse_type.delete_objc_prefix, - relationship.inverse_name - ] - else - inverse_properties << PROPERTY_INVERSE_MANY_TEMPLATE%[ - relationship.name.delete_inverse_suffix + 's', # 's' for plural form - relationship.inverse_type.delete_objc_prefix, - relationship.inverse_name - ] - inverse_properties << PROPERTY_INVERSE_ONE_TEMPLATE%[ - relationship.name.delete_inverse_suffix, - relationship.inverse_type.delete_objc_prefix, - relationship.name.delete_inverse_suffix + 's' # 's' for plural form - ] - end - end - end - return '' if inverse_properties.empty? - inverse_properties.map { |value| " #{value}\n" }.join + "\n" - end - - def generate_indexed_properties(entity) - indexed_properties = String.new - if entity.has_indexed_attributes? - indexed_properties << ' ' + '// Specify properties to index' + "\n" - indexed_properties << ' ' +'override static func indexedProperties() -> [String] {' + "\n" - indexed_properties << ' ' + 'return [' - entity.attributes.each do |_, attribute| - indexed_properties << ARRAY_TEMPLATE%[attribute.name.add_quotes] if attribute.indexed? - end - indexed_properties = indexed_properties[0..indexed_properties.length - 3] # delete last coma - indexed_properties << ']' + "\n" - indexed_properties << '}' + "\n\n" - end - indexed_properties - end - - end - end - end -end diff --git a/lib/gyro/realm/swift/object_mapper_generator.rb b/lib/gyro/realm/swift/object_mapper_generator.rb deleted file mode 100644 index c18f78d..0000000 --- a/lib/gyro/realm/swift/object_mapper_generator.rb +++ /dev/null @@ -1,120 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Realm - module Swift - module ObjectMapperGenerator - - # INCLUDES ############################################################# - - include Templates - - # PUBLIC METHODS ####################################################### - - def generate_object_mapper_categories(path, xcdatamodel, framework = false) - json_path = File.join(path, 'ObjectMapper') - Dir.mkdir(json_path) unless Dir.exists?(json_path) - xcdatamodel.entities.each do |_, entity| - generate_json_category_file(json_path, entity, framework) - end - end - - # PRIVATE METHODS ####################################################### - - def generate_json_category_file(path, entity, framework) - if !entity.attributes.empty? || !entity.relationships.empty? - source_file = generate_source_extension_file(entity) - file_name = EXTENSION_NAME%[entity.name] - Gyro.write_file_with_name(path, SOURCE_TEMPLATE%[file_name], source_file) unless source_file.empty? - end - end - - def generate_source_extension_file(entity) - source_file = String.new - source_file << GENERATED_MESSAGE + "\n\n" - source_file << IMPORT_OBJECT_MAPPER + "\n\n" - source_file << EXTENSION_TEMPLATE%[entity.name, "Mappable"] + "\n\n" - source_file << generate_init - source_file << generate_mapping(entity) - source_file << "}\n" - source_file - end - - def generate_mapping(entity) - source_file = String.new - source_file << " // MARK: Mappable\n\n" - source_file << " func mapping(map: Map) {\n" - source_file << generate_mapper_attributes(entity) if !entity.attributes.empty? - source_file << generate_mapper_relationships(entity) if !entity.relationships.empty? - source_file << " }\n" - source_file - end - - def generate_init() - source_file = String.new - source_file << " // MARK: Initializers\n\n" - source_file << " convenience init?(_ map: Map) {\n" - source_file << " self.init()\n" - source_file << " }\n\n" - source_file - end - - def generate_mapper_attributes(entity) - attributes = String.new - attributes << "\n // MARK: Attributes\n" - entity.attributes.each do |_, attribute| - attrKey = attribute.json_key_path.empty? ? attribute.name : attribute.json_key_path - case - when attribute.type == :date - transformer = attribute.transformer.empty? ? "ISO8601DateTransform" : attribute.transformer - attributes << " self." + attribute.name + " <- (map[" + attrKey.add_quotes + "], " + transformer + "())\n" - when attribute.type == :integer_16 && attribute.optional && attribute.enum_type == "" - attributes << " self." + attribute.name + " <- (map[" + attrKey.add_quotes + "], RealmOptionalInt16Transform())\n" - when attribute.type == :integer_32 && attribute.optional - attributes << " self." + attribute.name + " <- (map[" + attrKey.add_quotes + "], RealmOptionalInt32Transform())\n" - when attribute.type == :integer_64 && attribute.optional - attributes << " self." + attribute.name + " <- (map[" + attrKey.add_quotes + "], RealmOptionalInt64Transform())\n" - when attribute.type == :float && attribute.optional - attributes << " self." + attribute.name + " <- (map[" + attrKey.add_quotes + "], RealmOptionalFloatTransform())\n" - when attribute.type == :double && attribute.optional - attributes << " self." + attribute.name + " <- (map[" + attrKey.add_quotes + "], RealmOptionalDoubleTransform())\n" - when - attributes << " self." + attribute.name + " <- map[" + attrKey.add_quotes + "]\n" - end - end - attributes - end - - def generate_mapper_relationships(entity) - relationships = String.new - relationships << "\n // MARK: Relationships\n" - entity.relationships.each do |_, relationship| - next if relationship.inverse? - relationKey = relationship.json_key_path.empty? ? relationship.name : relationship.json_key_path - if relationship.type == :to_many - relationships << " self." + relationship.name + " <- (map[" + relationKey.add_quotes + "], ListTransform<" + relationship.inverse_type + ">())\n" - else - relationships << " self." + relationship.name + " <- map[" + relationKey.add_quotes + "]\n" - end - end - relationships - end - - end - end - end -end diff --git a/lib/gyro/realm/swift/templates.rb b/lib/gyro/realm/swift/templates.rb deleted file mode 100644 index 6aacea8..0000000 --- a/lib/gyro/realm/swift/templates.rb +++ /dev/null @@ -1,64 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Realm - module Swift - module Templates - - # COMMONS - GENERATED_MESSAGE = '/* DO NOT EDIT | Generated by gyro */' - - # IMPORTS - IMPORT_REALM = 'import RealmSwift' - SWIFT_FILE_TEMPLATE = '%s.swift' - IMPORT_OBJECT_MAPPER = 'import ObjectMapper' - - # ENUM - ENUM_STRING_DEF_TEMPLATE = 'enum %s: String {' - ENUM_STRING_CASE_TEMPLATE = 'case %s = "%s"' - - # CLASS - ARRAY_TEMPLATE ='%s, ' - CLASS_TEMPLATE = 'final class %s: Object {' - PROPERTY_DEFAULT_TEMPLATE = 'dynamic var %s: %s = %s' - PROPERTY_OBJECT_TEMPLATE = 'dynamic var %s: %s?' - PROPERTY_LIST_TEMPLATE = 'let %s = List<%s>()' - PROPERTY_LIST_VAR_TEMPLATE = 'var %s = List<%s>()' - PROPERTY_PRIVATE_ENUM_TEMPLATE = 'private dynamic var %s: String?' - PROPERTY_ENUM_TEMPLATE = 'dynamic var %s: String = ""' - PROPERTY_OPTIONAL_ENUM_TEMPLATE = 'dynamic var %s: String? = nil' - PROPERTY_COMPUTED_TEMPLATE = 'var %s: %s {' - PROPERTY_OPTIONAL_COMPUTED_TEMPLATE = 'var %s: %s? {' - PROPERTY_INVERSE_ONE_TEMPLATE = 'var %s: %s? { return %s.first }' - PROPERTY_INVERSE_MANY_TEMPLATE = 'let %s = LinkingObjects(fromType: %s.self, property: "%s")' - PROPERTY_OPTIONAL_NON_NUMBER_TEMPLATE = 'dynamic var %s: %s? = nil' - PROPERTY_OPTIONAL_NUMBER_TEMPLATE = 'let %s = RealmOptional<%s>()' - PROPERTY_OPTIONAL_NUMBER_VAR_TEMPLATE = 'var %s = RealmOptional<%s>()' - - # EXTENSION - EXTENSION_TEMPLATE = 'extension %s: %s {' - EXTENSION_NAME = '%sMapper' - SOURCE_TEMPLATE = '%s.swift' - - # COMMENTS - CLASS_COMMENT_TEMPLATE = "/**\n * %s\n */" - ATTRIBUTE_COMMENT_TEMPLATE = '/** %s */' - - end - end - end -end diff --git a/lib/gyro/template.rb b/lib/gyro/template.rb new file mode 100644 index 0000000..52fafe4 --- /dev/null +++ b/lib/gyro/template.rb @@ -0,0 +1,68 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module Gyro + # Gyro Template Helper + # + module Template + def self.print_list + Gyro::Template.directory.children.select(&:directory?).each do |entry| + puts " - #{entry.basename}" + end + end + + def self.print_infos(template) + readme = if template.include?('/') + Pathname.new(template) + 'README.md' + else + Gyro::Template.directory + template + 'README.md' + end + + Gyro::Log.fail!("No README.md found for template #{template}.") unless readme.exist? + puts readme.read + end + + def self.directory + Pathname.new(File.dirname(__FILE__)) + '../templates' + end + + def self.find(template_param) + if template_param.include? '/' + find_by_path(template_param) + else + find_by_name(template_param) + end + end + + def self.find_by_path(path) + template_dir = Pathname.new(path) + unless template_dir.exist? + Gyro::Log.fail!('You need to specify existing template directory using --template option' \ + ' (see --help for more info)') + end + + return template_dir if template_dir.directory? + return template_dir.dirname if template_dir.file? + Gyro::Log.fail!('You need to specify right template directory using --template option' \ + ' (see --help for more info)') + end + + def self.find_by_name(name) + template_dir = Gyro::Template.directory + name + return template_dir if template_dir.exist? + Gyro::Log.fail!('You need to specify existing default template name using --template option' \ + ' (see --help for more info)') + end + end +end diff --git a/lib/gyro/utils/error.rb b/lib/gyro/utils/error.rb deleted file mode 100644 index 20f604d..0000000 --- a/lib/gyro/utils/error.rb +++ /dev/null @@ -1,28 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Error - def self.raise(str) - Kernel.raise "\e[1;31m! #{str}\e[0m" - end - - def self.exit_with_error(message) - Gyro::Log::error message - exit 1 - end - end -end diff --git a/lib/gyro/utils/file_utils.rb b/lib/gyro/utils/file_utils.rb deleted file mode 100644 index 07c174f..0000000 --- a/lib/gyro/utils/file_utils.rb +++ /dev/null @@ -1,29 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - def self.find_xcdatamodel(dir) - Dir.chdir(dir) do - files = Dir.glob('*.xcdatamodel') - files.first.nil? ? nil : File.expand_path(files.first, dir) - end - end - - def self.write_file_with_name(dir, name_file, content) - file_path = File.expand_path(name_file, dir) - File.write(file_path, content) - end -end diff --git a/lib/gyro/utils/log.rb b/lib/gyro/utils/log.rb deleted file mode 100644 index 247f7bc..0000000 --- a/lib/gyro/utils/log.rb +++ /dev/null @@ -1,68 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module Log - - def self.title(str) # bg yellow - puts "\e[44;37m#{str}\e[0m" - end - - def self.error(str) - puts "\e[1;31m! #{str}\e[0m" - end - - def self.info(str) - puts "\e[1;33m> #{str}\e[0m" - end - - def self.success(str) - puts "\e[1;32m√ #{str}\e[0m" - end - - def self.prompt(str, url = nil) - prompt = "\e[1;36m ! #{str} [y/n]?\e[0m " - url_info = ' '*10 + "\e[0;37m (use '?' to show in browser)\e[0m" - print prompt - print "#{url_info}\r#{prompt}" if url - - answer = get_char do |c| - `open '#{url}'` if url && (c == '?') - "yn\003".include?(c.downcase) # \003 = ctrl-C - end - puts answer + (url ? ' '*url_info.length : '') - answer.downcase == 'y' - end - - private ###################################################################### - - def self.get_char - stop = false - typed_char = '' - begin - system('stty raw -echo') - until stop - typed_char = STDIN.getc.chr - stop = yield typed_char - end - ensure - system('stty -raw echo') - end - typed_char - end - - end -end diff --git a/lib/gyro/utils/string_xcdatamodel.rb b/lib/gyro/utils/string_xcdatamodel.rb deleted file mode 100644 index c9dc27d..0000000 --- a/lib/gyro/utils/string_xcdatamodel.rb +++ /dev/null @@ -1,58 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -class String - - def delete_objc_prefix - i = 0 - while i < self.length - 1 and /[[:upper:]]/.match(self[i+1]) - i += 1 - end - self[i..self.length] - end - - def delete_inverse_suffix - self.gsub('_', '') - end - - def capitalize_first_letter - self.slice(0, 1).capitalize + self.slice(1..-1) - end - - def camel_case - words = self.scan(/[A-Z][a-z]+/) - words.map!(&:upcase) - words.join('_') - end - - def underscore - self.gsub(/::/, '/'). - gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). - gsub(/([a-z\d])([A-Z])/, '\1_\2'). - tr('-', '_'). - downcase - end - - def add_quotes - "\"" + self + "\"" - end - - def add_parentheses - '(' + self + ')' - end - - -end diff --git a/lib/gyro/version.rb b/lib/gyro/version.rb index c51bd15..8ad998d 100644 --- a/lib/gyro/version.rb +++ b/lib/gyro/version.rb @@ -1,3 +1,19 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Gyro Version +# module Gyro - VERSION = '0.4.1' + VERSION = '1.0.0'.freeze end diff --git a/lib/gyro/xcdatamodel/parser.rb b/lib/gyro/xcdatamodel/parser.rb deleted file mode 100644 index 5cbb915..0000000 --- a/lib/gyro/xcdatamodel/parser.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'nokogiri' - -require 'gyro/xcdatamodel/parser/attribute' -require 'gyro/xcdatamodel/parser/relationship' -require 'gyro/xcdatamodel/parser/entity' -require 'gyro/xcdatamodel/parser/xcdatamodel' diff --git a/lib/gyro/xcdatamodel/parser/attribute.rb b/lib/gyro/xcdatamodel/parser/attribute.rb deleted file mode 100644 index 860aba0..0000000 --- a/lib/gyro/xcdatamodel/parser/attribute.rb +++ /dev/null @@ -1,98 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module XCDataModel - module Parser - - class Attribute - - attr_accessor :entity_name, :name, :type, :optional, :indexed, :default - attr_accessor :realm_ignored, :realm_read_only, :enum_type, :enum_values - attr_accessor :json_key_path, :json_values, :transformer, :comment, :support_annotation - - alias_method :optional?, :optional - alias_method :indexed?, :indexed - alias_method :realm_ignored?, :realm_ignored - - def initialize (attribute_xml, entity_name) - @entity_name = entity_name - @name = attribute_xml.xpath('@name').to_s - @optional = attribute_xml.xpath('@optional').to_s == 'YES' ? true : false - @indexed = attribute_xml.xpath('@indexed').to_s == 'YES' ? true : false - @default = attribute_xml.xpath('@defaultValueString').to_s - @type = attribute_xml.xpath('@attributeType').to_s.downcase.gsub(' ', '_').to_sym - @realm_ignored = attribute_xml.xpath(USERINFO_VALUE%['realmIgnored']).to_s.empty? ? false : true - @realm_read_only = attribute_xml.xpath(USERINFO_VALUE%['realmReadOnly']).to_s - @enum_type = attribute_xml.xpath(USERINFO_VALUE%['enumType']).to_s - @enum_values = attribute_xml.xpath(USERINFO_VALUE%['enumValues']).to_s.split(',') - @json_key_path = attribute_xml.xpath(USERINFO_VALUE%['JSONKeyPath']).to_s - @json_values = attribute_xml.xpath(USERINFO_VALUE%['JSONValues']).to_s.split(',') - @transformer = attribute_xml.xpath(USERINFO_VALUE%['transformer']).to_s.strip - @comment = attribute_xml.xpath(USERINFO_VALUE%['comment']).to_s - @support_annotation = attribute_xml.xpath(USERINFO_VALUE%['supportAnnotation']).to_s - search_for_error - end - - def enum? - !@enum_type.empty? - end - - def read_only? - !@realm_read_only.empty? - end - - def has_default? - !@default.empty? - end - - def to_s - "\tAttribute => name=#{@name} | type=#{@type} | optional=#{@optional} | default=#{@default} | indexed=#{@indexed}\n" - end - - def is_decimal? - @type == :decimal or @type == :double or @type == :float - end - - def is_integer? - @type == :integer_16 or @type == :integer_32 or @type == :integer_64 - end - - def is_number? - is_decimal? or is_integer? - end - - def is_bool? - @type == :boolean - end - - def need_transformer? - !@enum_type.empty? or @type == :boolean or @type == :date or !@transformer.empty? - end - - private ################################################################ - - def search_for_error - Gyro::Error::raise("The attribute \"%s\" from \"%s\" has no type - please fix it"%[@name, @entity_name]) if @type == :undefined || @type.empty? - Gyro::Error::raise("The attribute \"%s\" from \"%s\" is enum with incorrect type (not Integer) - please fix it"%[@name, @entity_name]) if !@enum_type.empty? and !@enum_values.empty? and !is_integer? - Gyro::Error::raise("The attribute \"%s\" from \"%s\" is wrongly annotated: when declaring an type with enum and JSONKeyPath, you must have the same number of items in the 'enumValues' and 'JSONValues' annotations - please fix it"%[@name, @entity_name]) if !@json_key_path.empty? and !@enum_values.empty? and @enum_values.size != @json_values.size - end - - end - - end - end -end diff --git a/lib/gyro/xcdatamodel/parser/entity.rb b/lib/gyro/xcdatamodel/parser/entity.rb deleted file mode 100644 index 2166d2b..0000000 --- a/lib/gyro/xcdatamodel/parser/entity.rb +++ /dev/null @@ -1,229 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module XCDataModel - module Parser - class Entity - - attr_accessor :name, :parent, :abstract, :attributes, :relationships, :identity_attribute, :comment - alias_method :abstract?, :abstract - - def initialize(entity_xml) - @name = entity_xml.xpath('@name').to_s - @parent = entity_xml.xpath('@parentEntity').to_s - @abstract = entity_xml.xpath('@isAbstract').to_s == 'YES' ? true : false - @clean = false - @identity_attribute = entity_xml.xpath(USERINFO_VALUE%['identityAttribute']).to_s - @comment = entity_xml.xpath(USERINFO_VALUE%['comment']).to_s - @attributes = Hash.new - @relationships = Hash.new - load_entity(entity_xml) - end - - def to_s - str = "\nEntity => #{@name}\n" - @attributes.each do |_, attribute| - str += attribute.to_s - end - @relationships.each do |_, relationship| - str += relationship.to_s - end - str - end - - def used_as_list_by_other?(entities) - entities.each do |_, entity| - entity.relationships.each do |_, relationship| - return true if relationship.inverse_type == @name and relationship.type == :to_many - end - end - false - end - - def has_list_attributes?(inverse = false) - @relationships.each do |_, relationship| - return true if relationship.type == :to_many and (!inverse ? !relationship.inverse? : true) - end - false - end - - def has_no_inverse_relationship? - @relationships.each do |_, relationship| - return true unless relationship.inverse? - end - false - end - - def has_ignored? - @attributes.each do |_, attribute| - return true if attribute.realm_ignored? - end - @relationships.each do |_, relationship| - return true if relationship.realm_ignored? - end - false - end - - def has_primary_key? - !@identity_attribute.empty? - end - - def has_required? - @attributes.each do |_, attribute| - return true if is_required?(attribute) - end - false - end - - def is_required?(attribute) - unless attribute.optional? - return true unless self.has_primary_key? - return true if self.has_primary_key? && !attribute.name.eql?(identity_attribute) - end - false - end - - def has_default_value?(attribute = @identity_attribute) - attribute.name != @identity_attribute - end - - def has_indexed_attributes? - @attributes.each do |_, attribute| - return true if attribute.indexed? - end - false - end - - def has_json_key_path? - @attributes.each do |_, attribute| - return true unless attribute.json_key_path.empty? - end - @relationships.each do |_, relationship| - return true if !relationship.inverse? and !relationship.json_key_path.empty? - end - false - end - - def has_enum_attributes? - @attributes.each do |_, attribute| - return true unless attribute.enum_type.empty? - end - false - end - - def transformers - transformers = Set.new - @attributes.each do |_, attribute| - transformers.add attribute.transformer unless attribute.transformer.empty? - end - transformers - end - - def has_custom_transformers? - @attributes.each do |_, attribute| - return true unless attribute.transformer.empty? - end - false - end - - def need_transformer? - has_enum_attributes? || has_bool_attributes? || has_custom_transformers? || has_date_attribute? - end - - def has_bool_attributes? - has_bool_attributes = false - @attributes.each do |_, attribute| - has_bool_attributes = true if attribute.type == :boolean - end - has_bool_attributes - end - - def has_number_attributes? - has_number_attributes = false - @attributes.each do |_, attribute| - if attribute.enum_type.empty? - case attribute.type - when :integer_16 then - has_number_attributes = true - when :integer_32 then - has_number_attributes = true - when :integer_64 then - has_number_attributes = true - when :decimal then - has_number_attributes = true - when :double then - has_number_attributes = true - when :float then - has_number_attributes = true - else - has_number_attributes = false - end - break if has_number_attributes - end - end - has_number_attributes - end - - def has_date_attribute? - @attributes.each do |_, attribute| - return true if attribute.type == :date - end - false - end - - def has_list_relationship? - @relationships.each do |_, relationship| - return true unless relationship.destination.empty? - end - false - end - - def has_only_inverse? - nb_inverses = 0 - @relationships.each do |_, relationship| - nb_inverses+=1 if relationship.inverse? - end - nb_inverses==@relationships.size - end - - private ################################################################ - - def load_entity(entity_xml) - load_attributes(entity_xml) - load_relationships(entity_xml) - end - - def load_attributes(entity_xml) - entity_xml.xpath('attribute').each do |node| - attribute = Attribute.new(node, @name) - if attribute.type != 'Transformable' - @attributes[attribute.name] = attribute - end - end - end - - def load_relationships(entity_xml) - entity_xml.xpath('relationship').each do |node| - relationship = Relationship.new(node, @name) - @relationships[relationship.name] = relationship - end - end - end - - end - end -end diff --git a/lib/gyro/xcdatamodel/parser/relationship.rb b/lib/gyro/xcdatamodel/parser/relationship.rb deleted file mode 100644 index b6c3566..0000000 --- a/lib/gyro/xcdatamodel/parser/relationship.rb +++ /dev/null @@ -1,68 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module XCDataModel - module Parser - - class Relationship - - attr_accessor :entity_name, :name, :type, :optional, :deletion_rule, :inverse_name, :inverse_type, :json_key_path, :support_annotation - attr_accessor :realm_ignored - attr_accessor :destination - - alias_method :realm_ignored?, :realm_ignored - - def initialize(relationship_xml, entity_name) - @entity_name = entity_name - @name = relationship_xml.xpath('@name').to_s - @optional = relationship_xml.xpath('@optional').to_s - @deletion_rule = relationship_xml.xpath('@deletionRule').to_s - @inverse_name = relationship_xml.xpath('@inverseName').to_s - @inverse_type = relationship_xml.xpath('@destinationEntity').to_s - @json_key_path = relationship_xml.xpath(USERINFO_VALUE%['JSONKeyPath']).to_s - @realm_ignored = relationship_xml.xpath(USERINFO_VALUE%['realmIgnored']).to_s.empty? ? false : true - @support_annotation = relationship_xml.xpath(USERINFO_VALUE%['supportAnnotation']).to_s - load_type(relationship_xml) - @destination = relationship_xml.xpath(USERINFO_VALUE%['destination']).to_s - search_for_error - end - - def to_s - "\tRelationship => name=#{@name} | type=#{@type} | optional=#{@optional} | deletion_rule=#{@deletion_rule}\n" - end - - def inverse? - @name.end_with?('_') - end - - private ################################################################ - - def load_type(relationship_xml) - max_count = relationship_xml.xpath('@maxCount').to_s - @type = (!max_count.nil? and max_count == '1') ? :to_one : :to_many - end - - def search_for_error - Gyro::Error::raise("The relationship \"%s\" from \"%s\" is wrong - please fix it"%[name, entity_name]) if inverse_type.empty? && destination.empty? - Gyro::Error::raise("The relationship \"%s\" from \"%s\" is wrong - please set a 'No Value' relationship as 'To Many'"%[name, entity_name]) if !destination.empty? && type != :to_many - end - - end - - end - end -end diff --git a/lib/gyro/xcdatamodel/parser/xcdatamodel.rb b/lib/gyro/xcdatamodel/parser/xcdatamodel.rb deleted file mode 100644 index ecc94f5..0000000 --- a/lib/gyro/xcdatamodel/parser/xcdatamodel.rb +++ /dev/null @@ -1,55 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -module Gyro - module XCDataModel - module Parser - USERINFO_VALUE = "userInfo/entry[@key='%s']/@value" - - class XCDataModel - - attr_accessor :entities - - def initialize(xcdatamodel_dir) - contents_file = File.join(xcdatamodel_dir, 'contents') - Gyro::Error::raise('Unable to find contents of xcdatamodel dir') unless File.exist?(contents_file) - @entities = Hash.new - file = File.open(contents_file) - document_xml = Nokogiri::XML(file).remove_namespaces! - file.close - load_entities(document_xml) - end - - def to_s - str = String.new - @entities.each do |_, value| - str += value.to_s - end - str - end - - private - - def load_entities(document_xml) - document_xml.xpath('//entity').each do |node| - entity = Entity.new(node) - @entities[entity.name] = entity - end - end - end - end - end -end diff --git a/lib/templates/android/README.md b/lib/templates/android/README.md new file mode 100644 index 0000000..a4f159e --- /dev/null +++ b/lib/templates/android/README.md @@ -0,0 +1,164 @@ +# Android Template Information + +| Name | Description | +| --------- | ----------------- | +| Folder name | templates/android | +| Invocation example | `gyro -m -t android …` | +| Language | Java | + +If you want to use this template you need to work with `Realm`. + +# Caracteristics + +In this template you have additional parameters to inject constants : + +- package (ex : **com.gyro.model.realm**) +- use_wrappers (define if you want to use wrapper types (ex Boolean) instead of primitive types (ex boolean) when you attribute is **optional** inside xcdatamodel) +- support_annotations (you can define annotation for properties ex : **@android.support.annotation.IntRange(from=0,to=255)** or **@android.support.annotation.Nullable**) + +# Usage + + +Package exemple : + +```bash +gyro -m -t android -o --param package:com.gyro.model.realm +``` + +Use wrappers exemple : + +```bash +gyro -m -t android -o --param use_wrappers:true +``` + +Support annotations exemple : + +```bash +gyro -m -t android -o --param support_annotations:true +``` + +And you can combine options : + +```bash +gyro -m -t android -o --param package:com.gyro.model.realm --param support_annotations:true --param use_wrappers:true +``` + + +# Generated Code + +Combine options : + +`FidelityCard.java`: + +```java +package com.gyro.model.realm; + +/* DO NOT EDIT | Generated by gyro */ + +import io.realm.RealmObject; + +public class FidelityCard extends RealmObject { + + public static final class Attributes { + public static final String IDENTIFIER = "identifier"; + public static final String POINTS = "points"; + + private Attributes() { + // Hide constructor + } + } + + public static final class Relationships { + public static final String USER = "user"; + + private Relationships() { + // Hide constructor + } + } + + private short identifier; + @android.support.annotation.IntRange(from=0,to=255) + private Integer points; + private User user; + + public short getIdentifier() { + return identifier; + } + + public void setIdentifier(final short identifier) { + this.identifier = identifier; + } + + @android.support.annotation.Nullable + @android.support.annotation.IntRange(from=0,to=255) + public Integer getPoints() { + return points; + } + + public void setPoints(@android.support.annotation.Nullable @android.support.annotation.IntRange(from=0,to=255) final Integer points) { + this.points = points; + } + + @android.support.annotation.NonNull + public User getUser() { + return user; + } + + public void setUser(@android.support.annotation.NonNull final User user) { + this.user = user; + } +} +``` + +Compare to generated code without options : + +`FidelityCard.java`: + +```java +/* DO NOT EDIT | Generated by gyro */ + +import io.realm.RealmObject; +import io.realm.annotations.PrimaryKey; + +public class Product extends RealmObject { + + public static final class Attributes { + public static final String BRAND = "brand"; + public static final String NAME = "name"; + public static final String PRICE = "price"; + + private Attributes() { + // Hide constructor + } + } + + private String brand; + @PrimaryKey + private String name; + private int price; + + public String getBrand() { + return brand; + } + + public void setBrand(final String brand) { + this.brand = brand; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public int getPrice() { + return price; + } + + public void setPrice(final int price) { + this.price = price; + } +} +``` \ No newline at end of file diff --git a/lib/templates/android/entity.liquid b/lib/templates/android/entity.liquid new file mode 100644 index 0000000..873eff6 --- /dev/null +++ b/lib/templates/android/entity.liquid @@ -0,0 +1,49 @@ +{%- if params.package.size > 0 -%} +package {{ params.package }}; +{%- endif %} + +/* DO NOT EDIT | Generated by gyro */ +{{ empty_line }} +{%- if entity.has_json_key_path == true %} +import com.google.gson.annotations.SerializedName; +{% comment %} *** Empty line *** {% endcomment %} +{%- endif %} +{%- if entity.has_date_attribute == true %} +import java.util.Date; +{%- endif %} +{%- if entity.has_list_relationship == true %} +import java.util.List; +{%- endif %} +{%- if entity.has_date_attribute == true or entity.has_list_relationship == true %} +{{ empty_line }} +{%- endif %} +{%- if entity.has_list_attributes == true %} +import io.realm.RealmList; +{%- endif %} +import io.realm.RealmObject; +{%- if entity.has_ignored == true %} +import io.realm.annotations.Ignore; +{%- endif %} +{%- if entity.has_indexed_attributes == true %} +import io.realm.annotations.Index; +{%- endif %} +{%- if entity.has_primary_key == true %} +import io.realm.annotations.PrimaryKey; +{%- endif %} + +{% if entity.comment.size > 0 -%} +/** + * {{ entity.comment }} + */ +{% endif %} +{%- assign primary_key = entity.identity_attribute -%} +public class {{ entity.name }} extends RealmObject { + + {%- include 'inc/attributes_enum' %} + {%- include 'inc/relationships_enum' %} + {% include 'inc/attributes_properties' %} + {%- include 'inc/relationships_properties' %} + {%- include 'inc/attributes_getter_setter' %} + {%- include 'inc/relationships_getter_setter' %} + {%- include 'inc/enum_getter_setter' %} +} diff --git a/lib/templates/android/entity_filename.liquid b/lib/templates/android/entity_filename.liquid new file mode 100644 index 0000000..8b3e3e1 --- /dev/null +++ b/lib/templates/android/entity_filename.liquid @@ -0,0 +1 @@ +{{params.prefix}}{{name}}.java \ No newline at end of file diff --git a/lib/templates/android/enum.liquid b/lib/templates/android/enum.liquid new file mode 100644 index 0000000..d59e696 --- /dev/null +++ b/lib/templates/android/enum.liquid @@ -0,0 +1,44 @@ +{%- if attribute.enum_type.size > 0 -%} + +{%- if params.package.size > 0 -%} +package {{ params.package }}; +{%- endif %} + +/* DO NOT EDIT | Generated by gyro */ + +public enum {{ attribute.enum_type }} { + {% for value in attribute.enum_values %} + {% if attribute.enum_values.size > 0 %} + {%- assign jsonKey = value -%} + {%- if attribute.json_values.size > 0 and attribute.json_values[forloop.index0] -%} + {%- assign jsonKey = attribute.json_values[forloop.index0] -%} + {%- endif -%} + {{ value | snake_case | upcase | strip }}("{{ jsonKey }}") + {%- if forloop.last == true -%};{%- else -%},{%- endif -%} + {%- endif -%} + {%- endfor %} + + private final String jsonValue; + + {{ attribute.enum_type }}(final String jsonValue) { + this.jsonValue = jsonValue; + } + {% if params.support_annotations.size > 0 %} + @android.support.annotation.Nullable + {%- endif %} + public static {{ attribute.enum_type }} get(final String jsonValue) { + for (final {{ attribute.enum_type }} type : {{ attribute.enum_type }}.values()) { + if (type.getJsonValue().equals(jsonValue)) { + return type; + } + } + return null; + } + {% if params.support_annotations.size > 0 %} + @android.support.annotation.NonNull + {%- endif %} + public String getJsonValue() { + return jsonValue; + } +} +{%- endif %} diff --git a/lib/templates/android/enum_filename.liquid b/lib/templates/android/enum_filename.liquid new file mode 100644 index 0000000..8b3e3e1 --- /dev/null +++ b/lib/templates/android/enum_filename.liquid @@ -0,0 +1 @@ +{{params.prefix}}{{name}}.java \ No newline at end of file diff --git a/lib/templates/android/inc/_attributes_enum.liquid b/lib/templates/android/inc/_attributes_enum.liquid new file mode 100644 index 0000000..b3b50a1 --- /dev/null +++ b/lib/templates/android/inc/_attributes_enum.liquid @@ -0,0 +1,17 @@ +{%- if entity.attributes.size > 0 %} + + public static final class Attributes { + {%- for attribute in entity.attributes -%} + {%- if attribute.realm_ignored == false or attribute.read_only == false -%} + {%- if attribute.comment.size > 0 %} + // {{ attribute.comment }} + {%- endif %} + public static final String {{ attribute.name | snake_case | upcase }} = "{{ attribute.name }}"; + {%- endif -%} + {%- endfor %} + + private Attributes() { + // Hide constructor + } + } +{%- endif -%} diff --git a/lib/templates/android/inc/_attributes_getter_setter.liquid b/lib/templates/android/inc/_attributes_getter_setter.liquid new file mode 100644 index 0000000..21d7ddc --- /dev/null +++ b/lib/templates/android/inc/_attributes_getter_setter.liquid @@ -0,0 +1,58 @@ +{%- for attribute in entity.attributes %} + + {%- if attribute.realm_read_only.size == 0 %} + {%- comment %} ******* CONVERT TYPE CAPTURE ******* {% endcomment -%} + + {%- capture visibility %} + {%- if attribute.enum_type.size > 0 and params.hide_members_with_enum.size > 0 -%} + protected + {%- else -%} + public + {%- endif %} + {%- endcapture %} + + {%- capture convert_type %} + {%- if attribute.realm_read_only.size == 0 and attribute.enum_type.size > 0 -%} + String + {%- else -%} + {%- if params.use_wrappers.size > 0 and attribute.optional == true -%} + {%- include 'inc/wrapper_type_converter' -%} + {%- else -%} + {%- include 'inc/type_converter' -%} + {%- endif %} + {%- endif %} + {%- endcapture %} + + {%- capture isPrimitives %} + {%- include 'inc/primitives' %} + {%- endcapture %} + + {%- capture annotation %} + {%- if params.support_annotations.size > 0 %} + {%- if isPrimitives == "false" -%} + {%- if params.use_wrappers.size > 0 or attribute.enum_type.size > 0 or isPrimitives == "false" -%} + @android.support.annotation.{% if attribute.optional == true %}Nullable{% else %}NonNull{%- endif -%} + {%- if attribute.support_annotation.size > 0 %}|{%- endif -%} + {%- endif -%} + {%- endif -%} + {%- if attribute.support_annotation.size > 0 -%} + @android.support.annotation.{{ attribute.support_annotation }} + {%- endif %} + {%- endif %} + {%- endcapture %} + {%- assign name = attribute.name %} + {{ empty_line }} + + {%- if annotation.size > 0 %} + {{ annotation | replace: "|"," + " }} + {%- endif %} + {{ visibility }} {{ convert_type }} get{{ name | titleize }}() { + return {{ name }}; + } + + {{ visibility }} void set{{ name | titleize }}({%- if annotation.size > 0 %}{{ annotation | replace: "|"," " }} {% endif %}final {{ convert_type }} {{ name }}) { + this.{{ name }} = {{ name }}; + } + {%- endif %} +{%- endfor %} \ No newline at end of file diff --git a/lib/templates/android/inc/_attributes_properties.liquid b/lib/templates/android/inc/_attributes_properties.liquid new file mode 100644 index 0000000..5f16fc9 --- /dev/null +++ b/lib/templates/android/inc/_attributes_properties.liquid @@ -0,0 +1,35 @@ + +{%- for attribute in entity.attributes -%} + {%- if attribute.realm_read_only.size == 0 -%} + {%- comment %} ******* CONVERT TYPE CAPTURE ******* {% endcomment -%} + {%- capture convert_type -%} + {%- if attribute.realm_read_only.size == 0 and attribute.enum_type.size > 0 -%} + String + {%- else -%} + {%- if params.use_wrappers == "true" and attribute.optional == true -%} + {%- include 'inc/wrapper_type_converter' -%} + {%- else -%} + {%- include 'inc/type_converter' -%} + {%- endif -%} + {%- endif -%} + {%- endcapture -%} + + {%- assign name = attribute.name -%} + {%- if name == primary_key %} + @PrimaryKey + {%- endif -%} + {%- if attribute.indexed == true %} + @Index + {%- endif -%} + {%- if attribute.realm_ignored == true %} + @Ignore + {%- endif -%} + {%- if attribute.json_key_path.size > 0 %} + @SerializedName("{{ attribute.json_key_path }}") + {%- endif -%} + {%- if params.support_annotations.size > 0 and attribute.support_annotation.size > 0 %} + @android.support.annotation.{{ attribute.support_annotation }} + {%- endif %} + private {{ convert_type }} {{ name }}; + {%- endif -%} +{%- endfor -%} \ No newline at end of file diff --git a/lib/templates/android/inc/_enum_getter_setter.liquid b/lib/templates/android/inc/_enum_getter_setter.liquid new file mode 100644 index 0000000..d8f7e36 --- /dev/null +++ b/lib/templates/android/inc/_enum_getter_setter.liquid @@ -0,0 +1,19 @@ +{%- for attribute in entity.attributes %} + + {%- if attribute.realm_read_only.size == 0 and attribute.enum_type.size > 0 %} + {% if params.support_annotations.size > 0 %} + @android.support.annotation.Nullable + {%- capture annotation -%}@android.support.annotation.NonNull {% endcapture -%} + {%- endif -%} + + {%- assign name = attribute.name %} + public {{ attribute.enum_type }} get{{ name | titleize }}Enum() { + return {{ attribute.enum_type }}.get(get{{ name | titleize }}()); + } + + public void set{{ name | titleize }}Enum({{ annotation }}final {{ attribute.enum_type }} {{ name }}) { + this.{{ name }} = {{ name }}.getJsonValue(); + } + {%- endif -%} + +{%- endfor -%} \ No newline at end of file diff --git a/lib/templates/android/inc/_primitives.liquid b/lib/templates/android/inc/_primitives.liquid new file mode 100644 index 0000000..a8c67c2 --- /dev/null +++ b/lib/templates/android/inc/_primitives.liquid @@ -0,0 +1,30 @@ +{%- capture convert_type %} + {%- if attribute.realm_read_only.size == 0 and attribute.enum_type.size > 0 -%} + String + {%- else -%} + {%- if params.use_wrappers.size > 0 and attribute.optional == true -%} + {%- include 'inc/wrapper_type_converter' -%} + {%- else -%} + {%- include 'inc/type_converter' -%} + {%- endif %} + {%- endif %} +{%- endcapture %} + +{%- case convert_type -%} +{%- when 'integer_16' or 'short' -%} +true +{%- when 'integer_32' or 'int' -%} +true +{%- when 'integer_64' or 'long' -%} +true +{%- when 'double' or 'decimal' -%} +true +{%- when 'float' -%} +true +{%- when 'boolean' -%} +true +{%- when 'binary' -%} +true +{%- else -%} +false +{%- endcase -%} \ No newline at end of file diff --git a/lib/templates/android/inc/_relationships_enum.liquid b/lib/templates/android/inc/_relationships_enum.liquid new file mode 100644 index 0000000..55a67fc --- /dev/null +++ b/lib/templates/android/inc/_relationships_enum.liquid @@ -0,0 +1,14 @@ +{%- if entity.relationships.size > 0 and entity.has_only_inverse == false %} + + public static final class Relationships { + {%- for relationship in entity.relationships -%} + {%- if relationship.inverse == false %} + public static final String {{ relationship.name | snake_case | upcase }} = "{{ relationship.name }}"; + {%- endif -%} + {%- endfor %} + + private Relationships() { + // Hide constructor + } + } +{%- endif -%} \ No newline at end of file diff --git a/lib/templates/android/inc/_relationships_getter_setter.liquid b/lib/templates/android/inc/_relationships_getter_setter.liquid new file mode 100644 index 0000000..faf2e04 --- /dev/null +++ b/lib/templates/android/inc/_relationships_getter_setter.liquid @@ -0,0 +1,47 @@ +{%- for relationship in entity.relationships %} + {%- if relationship.inverse == false %} + {%- capture relationship_type %} + {%- if relationship.realm_read_only.size == 0 and relationship.enum_type.size > 0 -%} + String + {%- else %} + {%- if relationship.destination.size == 0 %} + {%- if relationship.type != "to_many" -%} + {{ relationship.inverse_type }} + {%- else -%} + RealmList<{{ relationship.inverse_type }}> + {%- endif %} + {%- else -%} + List<{{ relationship.destination }}> + {%- endif %} + {%- endif %} + {%- endcapture %} + + {%- capture annotation %} + {%- if params.support_annotations.size > 0 %} + {%- if relationship.optional == true -%} + @android.support.annotation.Nullable + {%- endif %} + {%- if relationship.optional == false -%} + @android.support.annotation.NonNull + {%- endif %} + {%- if relationship.support_annotation.size > 0 -%} + |@android.support.annotation.{{ relationship.support_annotation }} + {%- endif %} + {%- endif %} + {%- endcapture %} + + {%- assign name = relationship.name %} + {% comment %} *** Empty line *** {% endcomment %} + {%- if annotation.size > 0 %} + {{ annotation | replace: "|"," + " }} + {%- endif %} + public {{ relationship_type }} get{{ name | titleize }}() { + return {{ name }}; + } + + public void set{{ name | titleize }}({%- if annotation.size > 0 %}{{ annotation | replace: "|"," " }} {% endif %}final {{ relationship_type }} {{ name }}) { + this.{{ name }} = {{ name }}; + } + {%- endif %} +{%- endfor %} \ No newline at end of file diff --git a/lib/templates/android/inc/_relationships_properties.liquid b/lib/templates/android/inc/_relationships_properties.liquid new file mode 100644 index 0000000..d338b6b --- /dev/null +++ b/lib/templates/android/inc/_relationships_properties.liquid @@ -0,0 +1,27 @@ +{%- for relationship in entity.relationships -%} + {%- capture relationship_type -%} + {%- if relationship.realm_read_only.size == 0 and relationship.enum_type.size > 0 -%} + String + {%- else -%} + {%- if relationship.destination.size == 0 -%} + {%- if relationship.type != "to_many" -%} + {{ relationship.inverse_type }} + {%- else -%} + RealmList<{{ relationship.inverse_type }}> + {%- endif -%} + {%- else -%} + List<{{ relationship.destination }}> + {%- endif -%} + {%- endif -%} + {%- endcapture -%} + + {%- if relationship.inverse == false -%} + {%- if relationship.realm_ignored == true %} + @Ignore + {%- endif -%} + {%- if relationship.json_key_path.size > 0 %} + @SerializedName("{{ relationship.json_key_path }}") + {%- endif %} + private {{ relationship_type }} {{ relationship.name }}; + {%- endif -%} +{%- endfor -%} \ No newline at end of file diff --git a/lib/templates/android/inc/_type_converter.liquid b/lib/templates/android/inc/_type_converter.liquid new file mode 100644 index 0000000..2d2cead --- /dev/null +++ b/lib/templates/android/inc/_type_converter.liquid @@ -0,0 +1,22 @@ +{%- case attribute.type -%} +{%- when 'integer_16' -%} +short +{%- when 'integer_32' -%} +int +{%- when 'integer_64' -%} +long +{%- when 'double' or 'decimal' -%} +double +{%- when 'float' -%} +float +{%- when 'string' -%} +String +{%- when 'boolean' -%} +boolean +{%- when 'date' -%} +Date +{%- when 'binary' -%} +byte[] +{%- else -%} +String +{%- endcase -%} \ No newline at end of file diff --git a/lib/templates/android/inc/_wrapper_type_converter.liquid b/lib/templates/android/inc/_wrapper_type_converter.liquid new file mode 100644 index 0000000..7edbd81 --- /dev/null +++ b/lib/templates/android/inc/_wrapper_type_converter.liquid @@ -0,0 +1,22 @@ +{%- case attribute.type -%} +{%- when 'integer_16' -%} +Short +{%- when 'integer_32' -%} +Integer +{%- when 'integer_64' -%} +Long +{%- when 'double' or 'decimal' -%} +Double +{%- when 'float' -%} +Float +{%- when 'string' -%} +String +{%- when 'boolean' -%} +Boolean +{%- when 'date' -%} +Date +{%- when 'binary' -%} +Byte[] +{%- else -%} +String +{%- endcase -%} \ No newline at end of file diff --git a/lib/templates/decodable/README.md b/lib/templates/decodable/README.md new file mode 100644 index 0000000..428a608 --- /dev/null +++ b/lib/templates/decodable/README.md @@ -0,0 +1,34 @@ +# Decodable Template Information + +| Name | Description | +| --------- | ----------------- | +| Folder name | templates/decodable | +| Invocation example | `gyro -m -t decodable …` | +| Language | Swift 3 | + +This template generate `Decodable` extension for each object of your data model. + +# Generated Code + +`Shop+Decodable.swift` : + +```swift +/* DO NOT EDIT | Generated by gyro */ + +import protocol Decodable.Decodable +import Decodable + +extension Shop: Decodable { + + static func decode(_ json: Any) throws -> Shop { + let shop = Shop() + shop.attrDate = try Date.decode(json => "attrDate") + shop.attrDateCustom = try Date.decode(json => "attrDateCustom") + shop.attrDouble = try json => "attrDouble" + shop.attrInteger16 = try Int.decode(json => "attrInteger16") + shop.attrInteger32 = try json => "attrInteger32" + shop.attrInteger64 = try Int.decode(json => "attrInteger64") + return shop + } +} +``` \ No newline at end of file diff --git a/lib/templates/decodable/entity.liquid b/lib/templates/decodable/entity.liquid new file mode 100644 index 0000000..32a514c --- /dev/null +++ b/lib/templates/decodable/entity.liquid @@ -0,0 +1,57 @@ +/* DO NOT EDIT | Generated by gyro */ + +import protocol Decodable.Decodable +import Decodable + +extension {{ entity.name }}: Decodable { + + static func decode(_ json: Any) throws -> {{ entity.name }} { + {%- assign entityVariable = entity.name | uncapitalize %} + let {{ entityVariable }} = {{ entity.name }}() + {%- for attribute in entity.attributes %} + {% assign attributeKey = attribute.name -%} + {%- if attribute.json_key_path.size > 0 -%} + {%- assign attributeKey = attribute.json_key_path -%} + {%- endif -%} + {%- case attribute.type -%} + {%- when "date" -%} + {{ entityVariable }}.{{ attribute.name }} = try Date.decode(json => "{{ attributeKey }}") + {%- when "integer_16" or "integer_32" or "integer_64" or "float" or "double" or "boolean" -%} + {%- if attribute.optional == true -%} + {%- if attribute.transformer.size > 0 -%} + {{ entityVariable }}.{{ attribute.name }}.value = try {{ attribute.transformer }}.decode(json => "{{ attributeKey }}") + {%- else -%} + {{ entityVariable }}.{{ attribute.name }}.value = try json => "{{ attributeKey }}" + {%- endif -%} + {%- else -%} + {%- if attribute.transformer.size > 0 -%} + {{ entityVariable }}.{{ attribute.name }} = try {{ attribute.transformer }}.decode(json => "{{ attributeKey }}") + {%- else -%} + {{ entityVariable }}.{{ attribute.name }} = try json => "{{ attributeKey }}" + {%- endif -%} + {%- endif -%} + {%- else -%} + {%- if attribute.transformer.size > 0 -%} + {{ entityVariable }}.{{ attribute.name }} = try {{ attribute.transformer }}.decode(json => "{{ attributeKey }}") + {%- else -%} + {{ entityVariable }}.{{ attribute.name }} = try json => "{{ attributeKey }}" + {%- endif -%} + {%- endcase -%} + {%- endfor -%} + + {%- for relationship in entity.relationships %} + {% assign relationKey = relationship.name -%} + {%- if relationship.json_key_path.size > 0 -%} + {%- assign relationKey = relationship.json_key_path -%} + {%- endif -%} + {%- if relationship.type == "to_many" -%} + let {{ relationship.name }}Sandbox: [{{ relationship.inverse_type }}] = try json => "{{ relationKey }}" + {{ entityVariable }}.{{ relationship.name }}.append(objectsIn: {{ relationship.name }}Sandbox) + {%- else -%} + {{ entityVariable }}.{{ relationship.name }} = try json => "{{ relationKey }}" + {%- endif -%} + {%- endfor %} + return {{ entityVariable }} + } + +} \ No newline at end of file diff --git a/lib/templates/decodable/entity_filename.liquid b/lib/templates/decodable/entity_filename.liquid new file mode 100644 index 0000000..a775a61 --- /dev/null +++ b/lib/templates/decodable/entity_filename.liquid @@ -0,0 +1 @@ +{{name}}+Decodable.swift \ No newline at end of file diff --git a/lib/templates/decodable/enum.liquid b/lib/templates/decodable/enum.liquid new file mode 100644 index 0000000..e69de29 diff --git a/lib/templates/decodable/enum_filename.liquid b/lib/templates/decodable/enum_filename.liquid new file mode 100644 index 0000000..e69de29 diff --git a/lib/templates/object-mapper/README.md b/lib/templates/object-mapper/README.md new file mode 100644 index 0000000..0e347dd --- /dev/null +++ b/lib/templates/object-mapper/README.md @@ -0,0 +1,40 @@ +# ObjectMapper Template Information + +| Name | Description | +| --------- | ----------------- | +| Folder name | templates/object-mapper | +| Invocation example | `gyro -m -t object-mapper …` | +| Language | Swift 3 | + +This template generate `ObjectMapper` extension for each object of your data model. + +# Generated Code + +`ShopMapper.swift` : + +```swift +/* DO NOT EDIT | Generated by gyro */ + +import ObjectMapper + +extension Shop: Mappable { + + // MARK: Initializers + convenience init?(map: Map) { + self.init() + } + + // MARK: Mappable + func mapping(map: Map) { + // MARK: Attributes + self.attrDate <- (map["attrDate"], ISO8601DateTransform()) + self.attrDateCustom <- (map["attrDateCustom"], CustomDateTransformer()) + self.attrDecimal <- (map["attrDecimal"], MPDecimalTransformer()) + self.attrDouble <- map["attrDouble"] + self.attrFloat <- (map["attrFloat"], MPDecimalTransformer()) + self.attrInteger16 <- (map["attrInteger16"], MPIntegerTransformer()) + self.attrInteger32 <- map["attrInteger32"] + self.attrInteger64 <- (map["attrInteger64"], MPIntegerTransformer()) + } +} +``` \ No newline at end of file diff --git a/lib/templates/object-mapper/entity.liquid b/lib/templates/object-mapper/entity.liquid new file mode 100644 index 0000000..40577c1 --- /dev/null +++ b/lib/templates/object-mapper/entity.liquid @@ -0,0 +1,66 @@ +/* DO NOT EDIT | Generated by gyro */ + +import ObjectMapper + +extension {{ entity.name }}: Mappable { + + // MARK: Initializers + convenience init?(map: Map) { + self.init() + } + + // MARK: Mappable + func mapping(map: Map) { + {%- if entity.attributes.size > 0 %} + // MARK: Attributes + {%- endif -%} + {%- for attribute in entity.attributes -%} + {% assign attributeKey = attribute.name -%} + {%- if attribute.json_key_path.size > 0 -%} + {%- assign attributeKey = attribute.json_key_path -%} + {%- endif -%} + + {%- case attribute.type -%} + {%- when "date" -%} + {%- assign transformer = "ISO8601DateTransform" -%} + {%- if attribute.transformer.size > 0 -%} + {%- assign transformer = attribute.transformer -%} + {%- endif %} + self.{{ attribute.name }} <- (map["{{ attributeKey }}"], {{ transformer }}()) + {%- when "integer_16" or "integer_32" or "integer_64" or "float" or "double" or "boolean" -%} + {%- if attribute.optional == true and attribute.enum_type.size == 0 %} + self.{{ attribute.name }}.value <- map["{{ attributeKey }}"] + {%- else %} + {%- if attribute.transformer.size > 0 %} + self.{{ attribute.name }} <- (map["{{ attributeKey }}"], {{ attribute.transformer }}()) + {%- else %} + self.{{ attribute.name }} <- map["{{ attributeKey }}"] + {%- endif %} + {%- endif -%} + {%- else %} + {%- if attribute.transformer.size > 0 %} + self.{{ attribute.name }} <- (map["{{ attributeKey }}"], {{ attribute.transformer }}()) + {%- else %} + self.{{ attribute.name }} <- map["{{ attributeKey }}"] + {%- endif %} + {%- endcase -%} + {%- endfor -%} + {%- if entity.relationships.size > 0 %} + + // MARK: Relationships + {%- endif -%} + {%- for relationship in entity.relationships -%} + {%- if relationship.inverse == false -%} + {% assign relationKey = relationship.name -%} + {%- if relationship.json_key_path.size > 0 -%} + {%- assign relationKey = relationship.json_key_path -%} + {%- endif -%} + {%- if relationship.type == "to_many" %} + self.{{ relationship.name }} <- (map["{{ relationKey }}"], ListTransform<{{ relationship.inverse_type }}>()) + {%- else %} + self.{{ relationship.name }} <- map["{{ relationKey }}"] + {%- endif -%} + {%- endif -%} + {%- endfor %} + } +} diff --git a/lib/templates/object-mapper/entity_filename.liquid b/lib/templates/object-mapper/entity_filename.liquid new file mode 100644 index 0000000..53e45f3 --- /dev/null +++ b/lib/templates/object-mapper/entity_filename.liquid @@ -0,0 +1 @@ +{{name}}Mapper.swift \ No newline at end of file diff --git a/lib/templates/object-mapper/enum.liquid b/lib/templates/object-mapper/enum.liquid new file mode 100644 index 0000000..e69de29 diff --git a/lib/templates/object-mapper/enum_filename.liquid b/lib/templates/object-mapper/enum_filename.liquid new file mode 100644 index 0000000..e69de29 diff --git a/lib/templates/swift3-variant/README.md b/lib/templates/swift3-variant/README.md new file mode 100644 index 0000000..52de289 --- /dev/null +++ b/lib/templates/swift3-variant/README.md @@ -0,0 +1,60 @@ +# Swift3 variant Template Information + +| Name | Description | +| --------- | ----------------- | +| Folder name | templates/swift3-variant | +| Invocation example | `gyro -m -t swift3-variant …` | +| Language | Swift 3 | + +# When to use it + +When you need to work with `ObjectMapper` and `Realm` together + +# Caracteristics + +In this template optional Realm objects (Attributes - RealmOptional - or Relationships - List<> -) are var properties : + +``` +// Attribute generation +{%- if attribute.is_number == true or attribute.is_bool == true %} + var {{ attribute.name }} = RealmOptional<{{ convert_type }}>() +{%- else %} + dynamic var {{ attribute.name }}: {{ convert_type }}? +{%- endif -%} + +// Relationship generation +{%- if relationship.inverse == false %} + {%- if relationship.type == "to_many" %} + var {{ relationship.name }} = List<{{ relationship.inverse_type }}>() + {%- else %} + dynamic var {{ relationship.name }}: {{ relationship.inverse_type }}? + {%- endif %} +{%- endif %} +``` + +# Generated Code + +`Product.swift` + +```swift +/* DO NOT EDIT | Generated by gyro */ + +import RealmSwift + +final class Product: Object { + + enum Attributes: String { + case brand = "brand" + case name = "name" + case price = "price" + case users = "users" + } + + dynamic var brand: String? + dynamic var name: String = "" + var price = RealmOptional() + + var users = List() +} + +``` \ No newline at end of file diff --git a/lib/templates/swift3-variant/entity.liquid b/lib/templates/swift3-variant/entity.liquid new file mode 100644 index 0000000..3532031 --- /dev/null +++ b/lib/templates/swift3-variant/entity.liquid @@ -0,0 +1,12 @@ +/* DO NOT EDIT | Generated by gyro */ + +import RealmSwift + +final class {{ entity.name }}: Object { + {%- include 'inc/attributes_enum' -%} + {% include 'inc/relationships_enum' -%} + {% include 'inc/attributes_properties' %} + {% include 'inc/primary_key' -%} + {% include 'inc/indexed_properties' -%} + {% include 'inc/ignored_properties' %} +} diff --git a/lib/templates/swift3-variant/entity_filename.liquid b/lib/templates/swift3-variant/entity_filename.liquid new file mode 100644 index 0000000..b5aadb1 --- /dev/null +++ b/lib/templates/swift3-variant/entity_filename.liquid @@ -0,0 +1 @@ +{{params.prefix}}{{name}}.swift \ No newline at end of file diff --git a/lib/templates/swift3-variant/enum.liquid b/lib/templates/swift3-variant/enum.liquid new file mode 100644 index 0000000..fa89a17 --- /dev/null +++ b/lib/templates/swift3-variant/enum.liquid @@ -0,0 +1,15 @@ +{%- if attribute.enum_type.size > 0 -%} +/* DO NOT EDIT | Generated by gyro */ + +enum {{ params.prefix }}{{ attribute.enum_type }}: String { +{%- for value in attribute.enum_values %} + {%- if attribute.enum_values.size > 0 %} + {% assign jsonKey = value -%} + {%- if attribute.json_values.size > 0 and attribute.json_values[forloop.index0] -%} + {%- assign jsonKey = attribute.json_values[forloop.index0] -%} + {%- endif -%} + case {{ value | uncapitalize }} = "{{ jsonKey | escape_quotes }}" + {%- endif %} +{%- endfor %} +} +{% endif %} \ No newline at end of file diff --git a/lib/templates/swift3-variant/enum_filename.liquid b/lib/templates/swift3-variant/enum_filename.liquid new file mode 100644 index 0000000..b5aadb1 --- /dev/null +++ b/lib/templates/swift3-variant/enum_filename.liquid @@ -0,0 +1 @@ +{{params.prefix}}{{name}}.swift \ No newline at end of file diff --git a/lib/templates/swift3-variant/inc/_attributes_enum.liquid b/lib/templates/swift3-variant/inc/_attributes_enum.liquid new file mode 100644 index 0000000..ca2c64d --- /dev/null +++ b/lib/templates/swift3-variant/inc/_attributes_enum.liquid @@ -0,0 +1,13 @@ + +{% if entity.attributes.size > 0 %} + enum Attributes: String { + {%- for attribute in entity.attributes -%} + {%- if attribute.realm_ignored or attribute.realm_read_only.size == 0 -%} + {%- if attribute.comment.size > 0 %} + /** {{ attribute.comment }} **/ + {%- endif %} + case {{ attribute.name }} = "{{ attribute.name | escape_quotes }}" + {%- endif %} + {%- endfor %} + } +{% endif -%} \ No newline at end of file diff --git a/lib/templates/swift3-variant/inc/_attributes_properties.liquid b/lib/templates/swift3-variant/inc/_attributes_properties.liquid new file mode 100644 index 0000000..6abca1d --- /dev/null +++ b/lib/templates/swift3-variant/inc/_attributes_properties.liquid @@ -0,0 +1,32 @@ +{%- for attribute in entity.attributes -%} + {%- comment %} ******* DEFAULT VALUE CAPTURE ******* {% endcomment -%} + {%- capture default_value -%} + {%- include 'inc/default_value_converter' -%} + {%- endcapture -%} + + {%- comment %} ******* CONVERT TYPE CAPTURE ******* {% endcomment -%} + {%- capture convert_type -%} + {%- include 'inc/type_converter' -%} + {%- endcapture -%} + + {%- if attribute.realm_read_only.size == 0 -%} + {%- if attribute.enum_values.size > 0 -%} + {%- comment -%} ******* GENERATE ENUM ATTRIBUTE PROPERTY ******* {% endcomment -%} + {%- include 'inc/enum_attribute_property' -%} + {%- else -%} + {%- if attribute.optional == true -%} + {% comment -%} ******* GENERATE OPTIONAL ATTRIBUTE PROPERTY ******* {% endcomment -%} + {%- include 'inc/optional_attribute_property' -%} + {%- else -%} + {%- comment -%} ******* GENERATE DEFAULT ATTRIBUTE PROPERTY ******* {% endcomment %} + dynamic var {{ attribute.name }}: {{ convert_type }} = {{ default_value }} + {%- endif -%} + {%- endif -%} + {%- endif -%} +{%- endfor -%} + +{%- comment %} ******* GENERATE RELATIONSHIP PROPERTIES ******* {% endcomment %} +{%- include 'inc/relationship_properties' -%} + +{%- comment %} ******* GENERATE INVERSE PROPERTIES ******* {% endcomment -%} +{%- include 'inc/inverse_properties' -%} \ No newline at end of file diff --git a/lib/templates/swift3-variant/inc/_default_value_converter.liquid b/lib/templates/swift3-variant/inc/_default_value_converter.liquid new file mode 100644 index 0000000..ad7c827 --- /dev/null +++ b/lib/templates/swift3-variant/inc/_default_value_converter.liquid @@ -0,0 +1,14 @@ +{%- case attribute.type -%} +{%- when 'integer_16' or 'integer_32' or 'integer_64' -%} +0 +{%- when 'float' or 'double' or 'decimal' -%} +0.0 +{%- when 'string' -%} +"" +{%- when 'boolean' -%} +false +{%- when 'date' -%} +Date() +{%- when 'binary' -%} +Data() +{%- endcase -%} \ No newline at end of file diff --git a/lib/templates/swift3-variant/inc/_enum_attribute_property.liquid b/lib/templates/swift3-variant/inc/_enum_attribute_property.liquid new file mode 100644 index 0000000..27bea03 --- /dev/null +++ b/lib/templates/swift3-variant/inc/_enum_attribute_property.liquid @@ -0,0 +1,26 @@ + {%- if attribute.optional == true %} + + dynamic var {{ attribute.name }}: String? + {%- else %} + + dynamic var {{ attribute.name }}: String = "" + {%- endif %} + {%- assign enum_type = attribute.enum_type %} + {%- assign enum_name = attribute.name %} + var {{ enum_name }}Enum: {{ enum_type }}? { + get { + {%- if attribute.optional == true %} + guard let {{ attribute.name }} = {{ attribute.name }}, + let enumValue = {{ enum_type }}(rawValue: {{ attribute.name }}) + else { return nil } + {%- else %} + guard let enumValue = {{ enum_type }}(rawValue: {{ attribute.name }}) else { return nil } + {%- endif %} + return enumValue + } + {%- if attribute.optional == true %} + set { {{ attribute.name }} = newValue?.rawValue ?? nil } + {%- else %} + set { {{ attribute.name }} = newValue?.rawValue ?? "" } + {%- endif %} + } diff --git a/lib/templates/swift3-variant/inc/_ignored_properties.liquid b/lib/templates/swift3-variant/inc/_ignored_properties.liquid new file mode 100644 index 0000000..570ed19 --- /dev/null +++ b/lib/templates/swift3-variant/inc/_ignored_properties.liquid @@ -0,0 +1,24 @@ +{%- if entity.has_ignored == true %} + // Specify properties to ignore (Realm won't persist these) + override static func ignoredProperties() -> [String] { + return [ + {%- capture enum_ignored_properties -%} + {%- for attribute in entity.attributes -%} + {%- if attribute.realm_ignored == true -%} + "{{ attribute.name }}", + {%- endif -%} + {%- endfor -%} + + {%- for relationship in entity.relationships -%} + {%- if relationship.realm_ignored == true -%} + "{{ relationship.name }}", + {%- endif -%} + {%- endfor -%} + {%- endcapture -%} + + {%- assign enum_ignored_properties_array = enum_ignored_properties | split: "," -%} + {%- for item in enum_ignored_properties_array -%} + {{ item }}{%- if forloop.last == false -%},{%- endif -%} + {%- endfor -%}] + } +{% endif -%} \ No newline at end of file diff --git a/lib/templates/swift3-variant/inc/_indexed_properties.liquid b/lib/templates/swift3-variant/inc/_indexed_properties.liquid new file mode 100644 index 0000000..ffd1eaa --- /dev/null +++ b/lib/templates/swift3-variant/inc/_indexed_properties.liquid @@ -0,0 +1,19 @@ +{%- if entity.has_indexed_attributes == true %} + // Specify properties to index + override static func indexedProperties() -> [String] { + return [ + {%- capture enum_indexed_properties -%} + {%- for attribute in entity.attributes -%} + {%- if attribute.is_indexed == true -%} + "{{attribute.name}}", + {%- endif %} + {%- endfor %} + {%- endcapture -%} + + {%- assign enum_indexed_properties_array = enum_indexed_properties | split: "," -%} + {%- assign enum_indexed_properties_array_size = enum_indexed_properties_array | size | minus: 1 -%} + {%- for item in enum_indexed_properties_array limit:enum_indexed_properties_array_size -%} + {{ item }}{%- if forloop.last == false -%},{%- endif -%} + {%- endfor -%}] + } +{%- endif -%} \ No newline at end of file diff --git a/lib/templates/swift3-variant/inc/_inverse_properties.liquid b/lib/templates/swift3-variant/inc/_inverse_properties.liquid new file mode 100644 index 0000000..ade8a47 --- /dev/null +++ b/lib/templates/swift3-variant/inc/_inverse_properties.liquid @@ -0,0 +1,11 @@ +{%- for relationship in entity.relationships -%} + {%- if relationship.inverse == true %} + {% assign name_size = relationship.name | size | minus: 1 %} + {%- if relationship.type == "to_many" %} + let {{ relationship.name | truncate: name_size, '' }}s = LinkingObjects(fromType: {{ relationship.inverse_type }}.self, property: "{{ relationship.inverse_name }}") + {%- else %} + let {{ relationship.name | truncate: name_size, '' }}s = LinkingObjects(fromType: {{ relationship.inverse_type }}.self, property: "{{ relationship.inverse_name }}") + var {{ relationship.name | truncate: name_size, '' }}: {{ relationship.inverse_type }}? { return {{ relationship.name | truncate: name_size, '' }}s.first } + {%- endif -%} + {%- endif -%} +{%- endfor -%} \ No newline at end of file diff --git a/lib/templates/swift3-variant/inc/_optional_attribute_property.liquid b/lib/templates/swift3-variant/inc/_optional_attribute_property.liquid new file mode 100644 index 0000000..ae6c1dd --- /dev/null +++ b/lib/templates/swift3-variant/inc/_optional_attribute_property.liquid @@ -0,0 +1,5 @@ +{%- if attribute.is_number == true or attribute.is_bool == true %} + var {{ attribute.name }} = RealmOptional<{{ convert_type }}>() +{%- else %} + dynamic var {{ attribute.name }}: {{ convert_type }}? +{%- endif -%} \ No newline at end of file diff --git a/lib/templates/swift3-variant/inc/_primary_key.liquid b/lib/templates/swift3-variant/inc/_primary_key.liquid new file mode 100644 index 0000000..a48a7a2 --- /dev/null +++ b/lib/templates/swift3-variant/inc/_primary_key.liquid @@ -0,0 +1,5 @@ +{%- if entity.has_primary_key == true %} + override static func primaryKey() -> String? { + return "{{ entity.identity_attribute }}" + } +{% endif -%} \ No newline at end of file diff --git a/lib/templates/swift3-variant/inc/_relationship_properties.liquid b/lib/templates/swift3-variant/inc/_relationship_properties.liquid new file mode 100644 index 0000000..85ccb17 --- /dev/null +++ b/lib/templates/swift3-variant/inc/_relationship_properties.liquid @@ -0,0 +1,9 @@ +{%- for relationship in entity.relationships -%} +{%- if relationship.inverse == false %} + {%- if relationship.type == "to_many" %} + var {{ relationship.name }} = List<{{ relationship.inverse_type }}>() + {%- else %} + dynamic var {{ relationship.name }}: {{ relationship.inverse_type }}? + {%- endif %} +{%- endif %} +{%- endfor -%} \ No newline at end of file diff --git a/lib/templates/swift3-variant/inc/_relationships_enum.liquid b/lib/templates/swift3-variant/inc/_relationships_enum.liquid new file mode 100644 index 0000000..fb654ae --- /dev/null +++ b/lib/templates/swift3-variant/inc/_relationships_enum.liquid @@ -0,0 +1,17 @@ +{%- if entity.relationships.size > 0 and entity.has_only_inverse == false %} + enum Relationships: String { + {%- for relationship in entity.relationships %} + {%- capture relationship_name -%} + {%- if relationship.inverse == true -%} + {%- assign name_size = relationship.name | size | minus: 1 -%} + {{ relationship.name | truncate: name_size, '' }} + {%- if relationship.type == "to_many" -%}s{%- endif -%} + {%- else -%} + {{ relationship.name }} + {%- endif -%} + {%- endcapture -%} + {%- assign relationship_name = relationship_name %} + case {{ relationship_name | uncapitalize }} = "{{ relationship_name | escape_quotes }}" + {%- endfor %} + } +{% endif -%} \ No newline at end of file diff --git a/lib/templates/swift3-variant/inc/_type_converter.liquid b/lib/templates/swift3-variant/inc/_type_converter.liquid new file mode 100644 index 0000000..3f69c2c --- /dev/null +++ b/lib/templates/swift3-variant/inc/_type_converter.liquid @@ -0,0 +1,20 @@ +{%- case attribute.type -%} +{%- when 'integer_16' -%} +Int16 +{%- when 'integer_32' -%} +Int32 +{%- when 'integer_64' -%} +Int64 +{%- when 'double' or 'decimal' -%} +Double +{%- when 'float' -%} +Float +{%- when 'string' -%} +String +{%- when 'boolean' -%} +Bool +{%- when 'date' -%} +Date +{%- when 'binary' -%} +Data +{%- endcase -%} \ No newline at end of file diff --git a/lib/templates/swift3/README.md b/lib/templates/swift3/README.md new file mode 100644 index 0000000..abcd5df --- /dev/null +++ b/lib/templates/swift3/README.md @@ -0,0 +1,60 @@ +# Swift3 Template Information + +| Name | Description | +| --------- | ----------------- | +| Folder name | templates/swift3 | +| Invocation example | `gyro -m -t swift3 …` | +| Language | Swift 3 | + +# When to use it + +This template is the reference for swift 3 with Realm generation code. +You can use it when you need to work with `Realm` + +# Caracteristics + +In this template optional Realm objects (Attributes - RealmOptional - or Relationships - List<> -) are `let` properties (conform to the Realm documentation) : + +``` +// Attribute generation +{%- if attribute.is_number == true or attribute.is_bool == true %} + let {{ attribute.name }} = RealmOptional<{{ convert_type }}>() +{%- else %} + dynamic var {{ attribute.name }}: {{ convert_type }}? +{%- endif -%} + +// Relationship generation +{%- if relationship.inverse == false %} + {%- if relationship.type == "to_many" %} + let {{ relationship.name }} = List<{{ relationship.inverse_type }}>() + {%- else %} + dynamic var {{ relationship.name }}: {{ relationship.inverse_type }}? + {%- endif %} +{%- endif %} +``` + +# Generated Code + +`Product.swift` : + +```swift +/* DO NOT EDIT | Generated by gyro */ + +import RealmSwift + +final class Product: Object { + + enum Attributes: String { + case brand = "brand" + case name = "name" + case price = "price" + case users = "users" + } + + dynamic var brand: String? + dynamic var name: String = "" + let price = RealmOptional() + + let users = List() +} +``` \ No newline at end of file diff --git a/lib/templates/swift3/entity.liquid b/lib/templates/swift3/entity.liquid new file mode 100644 index 0000000..3532031 --- /dev/null +++ b/lib/templates/swift3/entity.liquid @@ -0,0 +1,12 @@ +/* DO NOT EDIT | Generated by gyro */ + +import RealmSwift + +final class {{ entity.name }}: Object { + {%- include 'inc/attributes_enum' -%} + {% include 'inc/relationships_enum' -%} + {% include 'inc/attributes_properties' %} + {% include 'inc/primary_key' -%} + {% include 'inc/indexed_properties' -%} + {% include 'inc/ignored_properties' %} +} diff --git a/lib/templates/swift3/entity_filename.liquid b/lib/templates/swift3/entity_filename.liquid new file mode 100644 index 0000000..b5aadb1 --- /dev/null +++ b/lib/templates/swift3/entity_filename.liquid @@ -0,0 +1 @@ +{{params.prefix}}{{name}}.swift \ No newline at end of file diff --git a/lib/templates/swift3/enum.liquid b/lib/templates/swift3/enum.liquid new file mode 100644 index 0000000..fa89a17 --- /dev/null +++ b/lib/templates/swift3/enum.liquid @@ -0,0 +1,15 @@ +{%- if attribute.enum_type.size > 0 -%} +/* DO NOT EDIT | Generated by gyro */ + +enum {{ params.prefix }}{{ attribute.enum_type }}: String { +{%- for value in attribute.enum_values %} + {%- if attribute.enum_values.size > 0 %} + {% assign jsonKey = value -%} + {%- if attribute.json_values.size > 0 and attribute.json_values[forloop.index0] -%} + {%- assign jsonKey = attribute.json_values[forloop.index0] -%} + {%- endif -%} + case {{ value | uncapitalize }} = "{{ jsonKey | escape_quotes }}" + {%- endif %} +{%- endfor %} +} +{% endif %} \ No newline at end of file diff --git a/lib/templates/swift3/enum_filename.liquid b/lib/templates/swift3/enum_filename.liquid new file mode 100644 index 0000000..b5aadb1 --- /dev/null +++ b/lib/templates/swift3/enum_filename.liquid @@ -0,0 +1 @@ +{{params.prefix}}{{name}}.swift \ No newline at end of file diff --git a/lib/templates/swift3/inc/_attributes_enum.liquid b/lib/templates/swift3/inc/_attributes_enum.liquid new file mode 100644 index 0000000..ca2c64d --- /dev/null +++ b/lib/templates/swift3/inc/_attributes_enum.liquid @@ -0,0 +1,13 @@ + +{% if entity.attributes.size > 0 %} + enum Attributes: String { + {%- for attribute in entity.attributes -%} + {%- if attribute.realm_ignored or attribute.realm_read_only.size == 0 -%} + {%- if attribute.comment.size > 0 %} + /** {{ attribute.comment }} **/ + {%- endif %} + case {{ attribute.name }} = "{{ attribute.name | escape_quotes }}" + {%- endif %} + {%- endfor %} + } +{% endif -%} \ No newline at end of file diff --git a/lib/templates/swift3/inc/_attributes_properties.liquid b/lib/templates/swift3/inc/_attributes_properties.liquid new file mode 100644 index 0000000..6abca1d --- /dev/null +++ b/lib/templates/swift3/inc/_attributes_properties.liquid @@ -0,0 +1,32 @@ +{%- for attribute in entity.attributes -%} + {%- comment %} ******* DEFAULT VALUE CAPTURE ******* {% endcomment -%} + {%- capture default_value -%} + {%- include 'inc/default_value_converter' -%} + {%- endcapture -%} + + {%- comment %} ******* CONVERT TYPE CAPTURE ******* {% endcomment -%} + {%- capture convert_type -%} + {%- include 'inc/type_converter' -%} + {%- endcapture -%} + + {%- if attribute.realm_read_only.size == 0 -%} + {%- if attribute.enum_values.size > 0 -%} + {%- comment -%} ******* GENERATE ENUM ATTRIBUTE PROPERTY ******* {% endcomment -%} + {%- include 'inc/enum_attribute_property' -%} + {%- else -%} + {%- if attribute.optional == true -%} + {% comment -%} ******* GENERATE OPTIONAL ATTRIBUTE PROPERTY ******* {% endcomment -%} + {%- include 'inc/optional_attribute_property' -%} + {%- else -%} + {%- comment -%} ******* GENERATE DEFAULT ATTRIBUTE PROPERTY ******* {% endcomment %} + dynamic var {{ attribute.name }}: {{ convert_type }} = {{ default_value }} + {%- endif -%} + {%- endif -%} + {%- endif -%} +{%- endfor -%} + +{%- comment %} ******* GENERATE RELATIONSHIP PROPERTIES ******* {% endcomment %} +{%- include 'inc/relationship_properties' -%} + +{%- comment %} ******* GENERATE INVERSE PROPERTIES ******* {% endcomment -%} +{%- include 'inc/inverse_properties' -%} \ No newline at end of file diff --git a/lib/templates/swift3/inc/_default_value_converter.liquid b/lib/templates/swift3/inc/_default_value_converter.liquid new file mode 100644 index 0000000..ad7c827 --- /dev/null +++ b/lib/templates/swift3/inc/_default_value_converter.liquid @@ -0,0 +1,14 @@ +{%- case attribute.type -%} +{%- when 'integer_16' or 'integer_32' or 'integer_64' -%} +0 +{%- when 'float' or 'double' or 'decimal' -%} +0.0 +{%- when 'string' -%} +"" +{%- when 'boolean' -%} +false +{%- when 'date' -%} +Date() +{%- when 'binary' -%} +Data() +{%- endcase -%} \ No newline at end of file diff --git a/lib/templates/swift3/inc/_enum_attribute_property.liquid b/lib/templates/swift3/inc/_enum_attribute_property.liquid new file mode 100644 index 0000000..5e9697b --- /dev/null +++ b/lib/templates/swift3/inc/_enum_attribute_property.liquid @@ -0,0 +1,26 @@ + {%- if attribute.optional == true %} + + dynamic var {{ attribute.name }}: String? + {%- else %} + + dynamic var {{ attribute.name }}: String = "" + {%- endif %} + {%- assign enum_type = attribute.enum_type %} + {%- assign enum_name = attribute.name %} + var {{ enum_name }}Enum: {{ enum_type | delete_objc_prefix }}? { + get { + {%- if attribute.optional == true %} + guard let {{ attribute.name }} = {{ attribute.name }}, + let enumValue = {{ enum_type }}(rawValue: {{ attribute.name }}) + else { return nil } + {%- else %} + guard let enumValue = {{ enum_type }}(rawValue: {{ attribute.name }}) else { return nil } + {%- endif %} + return enumValue + } + {%- if attribute.optional == true %} + set { {{ attribute.name }} = newValue?.rawValue ?? nil } + {%- else %} + set { {{ attribute.name }} = newValue?.rawValue ?? "" } + {%- endif %} + } diff --git a/lib/templates/swift3/inc/_ignored_properties.liquid b/lib/templates/swift3/inc/_ignored_properties.liquid new file mode 100644 index 0000000..570ed19 --- /dev/null +++ b/lib/templates/swift3/inc/_ignored_properties.liquid @@ -0,0 +1,24 @@ +{%- if entity.has_ignored == true %} + // Specify properties to ignore (Realm won't persist these) + override static func ignoredProperties() -> [String] { + return [ + {%- capture enum_ignored_properties -%} + {%- for attribute in entity.attributes -%} + {%- if attribute.realm_ignored == true -%} + "{{ attribute.name }}", + {%- endif -%} + {%- endfor -%} + + {%- for relationship in entity.relationships -%} + {%- if relationship.realm_ignored == true -%} + "{{ relationship.name }}", + {%- endif -%} + {%- endfor -%} + {%- endcapture -%} + + {%- assign enum_ignored_properties_array = enum_ignored_properties | split: "," -%} + {%- for item in enum_ignored_properties_array -%} + {{ item }}{%- if forloop.last == false -%},{%- endif -%} + {%- endfor -%}] + } +{% endif -%} \ No newline at end of file diff --git a/lib/templates/swift3/inc/_indexed_properties.liquid b/lib/templates/swift3/inc/_indexed_properties.liquid new file mode 100644 index 0000000..74cdc3a --- /dev/null +++ b/lib/templates/swift3/inc/_indexed_properties.liquid @@ -0,0 +1,19 @@ +{%- if entity.has_indexed_attributes == true %} + // Specify properties to index + override static func indexedProperties() -> [String] { + return [ + {%- capture enum_indexed_properties -%} + {%- for attribute in entity.attributes -%} + {%- if attribute.is_indexed == true -%} + "{{attribute.name}}", + {%- endif %} + {%- endfor %} + {%- endcapture -%} + + {%- assign enum_indexed_properties_array = enum_indexed_properties | split: "," -%} + {%- assign enum_indexed_properties_array_size = enum_indexed_properties_array | size | minus: 1 -%} + {%- for item in enum_indexed_properties_array limit:enum_indexed_properties_array_size -%} + {{ item }}{%- if forloop.last == false -%},{%- endif -%} + {%- endfor -%}] + } +{%- endif -%} \ No newline at end of file diff --git a/lib/templates/swift3/inc/_inverse_properties.liquid b/lib/templates/swift3/inc/_inverse_properties.liquid new file mode 100644 index 0000000..ade8a47 --- /dev/null +++ b/lib/templates/swift3/inc/_inverse_properties.liquid @@ -0,0 +1,11 @@ +{%- for relationship in entity.relationships -%} + {%- if relationship.inverse == true %} + {% assign name_size = relationship.name | size | minus: 1 %} + {%- if relationship.type == "to_many" %} + let {{ relationship.name | truncate: name_size, '' }}s = LinkingObjects(fromType: {{ relationship.inverse_type }}.self, property: "{{ relationship.inverse_name }}") + {%- else %} + let {{ relationship.name | truncate: name_size, '' }}s = LinkingObjects(fromType: {{ relationship.inverse_type }}.self, property: "{{ relationship.inverse_name }}") + var {{ relationship.name | truncate: name_size, '' }}: {{ relationship.inverse_type }}? { return {{ relationship.name | truncate: name_size, '' }}s.first } + {%- endif -%} + {%- endif -%} +{%- endfor -%} \ No newline at end of file diff --git a/lib/templates/swift3/inc/_optional_attribute_property.liquid b/lib/templates/swift3/inc/_optional_attribute_property.liquid new file mode 100644 index 0000000..df45805 --- /dev/null +++ b/lib/templates/swift3/inc/_optional_attribute_property.liquid @@ -0,0 +1,5 @@ +{%- if attribute.is_number == true or attribute.is_bool == true %} + let {{ attribute.name }} = RealmOptional<{{ convert_type }}>() +{%- else %} + dynamic var {{ attribute.name }}: {{ convert_type }}? +{%- endif -%} \ No newline at end of file diff --git a/lib/templates/swift3/inc/_primary_key.liquid b/lib/templates/swift3/inc/_primary_key.liquid new file mode 100644 index 0000000..a48a7a2 --- /dev/null +++ b/lib/templates/swift3/inc/_primary_key.liquid @@ -0,0 +1,5 @@ +{%- if entity.has_primary_key == true %} + override static func primaryKey() -> String? { + return "{{ entity.identity_attribute }}" + } +{% endif -%} \ No newline at end of file diff --git a/lib/templates/swift3/inc/_relationship_properties.liquid b/lib/templates/swift3/inc/_relationship_properties.liquid new file mode 100644 index 0000000..9b2a75b --- /dev/null +++ b/lib/templates/swift3/inc/_relationship_properties.liquid @@ -0,0 +1,9 @@ +{%- for relationship in entity.relationships -%} +{%- if relationship.inverse == false %} + {%- if relationship.type == "to_many" %} + let {{ relationship.name }} = List<{{ relationship.inverse_type }}>() + {%- else %} + dynamic var {{ relationship.name }}: {{ relationship.inverse_type }}? + {%- endif %} +{%- endif %} +{%- endfor -%} \ No newline at end of file diff --git a/lib/templates/swift3/inc/_relationships_enum.liquid b/lib/templates/swift3/inc/_relationships_enum.liquid new file mode 100644 index 0000000..fb654ae --- /dev/null +++ b/lib/templates/swift3/inc/_relationships_enum.liquid @@ -0,0 +1,17 @@ +{%- if entity.relationships.size > 0 and entity.has_only_inverse == false %} + enum Relationships: String { + {%- for relationship in entity.relationships %} + {%- capture relationship_name -%} + {%- if relationship.inverse == true -%} + {%- assign name_size = relationship.name | size | minus: 1 -%} + {{ relationship.name | truncate: name_size, '' }} + {%- if relationship.type == "to_many" -%}s{%- endif -%} + {%- else -%} + {{ relationship.name }} + {%- endif -%} + {%- endcapture -%} + {%- assign relationship_name = relationship_name %} + case {{ relationship_name | uncapitalize }} = "{{ relationship_name | escape_quotes }}" + {%- endfor %} + } +{% endif -%} \ No newline at end of file diff --git a/lib/templates/swift3/inc/_type_converter.liquid b/lib/templates/swift3/inc/_type_converter.liquid new file mode 100644 index 0000000..3f69c2c --- /dev/null +++ b/lib/templates/swift3/inc/_type_converter.liquid @@ -0,0 +1,20 @@ +{%- case attribute.type -%} +{%- when 'integer_16' -%} +Int16 +{%- when 'integer_32' -%} +Int32 +{%- when 'integer_64' -%} +Int64 +{%- when 'double' or 'decimal' -%} +Double +{%- when 'float' -%} +Float +{%- when 'string' -%} +String +{%- when 'boolean' -%} +Bool +{%- when 'date' -%} +Date +{%- when 'binary' -%} +Data +{%- endcase -%} \ No newline at end of file diff --git a/spec/fixtures/java/annotations/FidelityCard.java b/spec/fixtures/java/annotations/FidelityCard.java index cd97630..3acfff2 100644 --- a/spec/fixtures/java/annotations/FidelityCard.java +++ b/spec/fixtures/java/annotations/FidelityCard.java @@ -1,18 +1,26 @@ package com.gyro.tests; -import io.realm.RealmObject; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class FidelityCard extends RealmObject { - public interface Attributes { - String IDENTIFIER = "identifier"; - String POINTS = "points"; + public static final class Attributes { + public static final String IDENTIFIER = "identifier"; + public static final String POINTS = "points"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String USER = "user"; + public static final class Relationships { + public static final String USER = "user"; + + private Relationships() { + // Hide constructor + } } private short identifier; @@ -37,12 +45,12 @@ public void setPoints(@android.support.annotation.IntRange(from=0,to=255) final this.points = points; } - @android.support.annotation.Nullable + @android.support.annotation.NonNull public User getUser() { return user; } - public void setUser(@android.support.annotation.Nullable final User user) { + public void setUser(@android.support.annotation.NonNull final User user) { this.user = user; } } diff --git a/spec/fixtures/java/annotations/Product.java b/spec/fixtures/java/annotations/Product.java index 64beeca..1b07608 100644 --- a/spec/fixtures/java/annotations/Product.java +++ b/spec/fixtures/java/annotations/Product.java @@ -1,26 +1,31 @@ package com.gyro.tests; -import io.realm.RealmObject; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class Product extends RealmObject { - public interface Attributes { - String BRAND = "brand"; - String NAME = "name"; - String PRICE = "price"; + public static final class Attributes { + public static final String BRAND = "brand"; + public static final String NAME = "name"; + public static final String PRICE = "price"; + + private Attributes() { + // Hide constructor + } } private String brand; private String name; private int price; + @android.support.annotation.Nullable public String getBrand() { return brand; } - public void setBrand(final String brand) { + public void setBrand(@android.support.annotation.Nullable final String brand) { this.brand = brand; } diff --git a/spec/fixtures/java/annotations/Shop.java b/spec/fixtures/java/annotations/Shop.java index dd12a2b..440cf2f 100644 --- a/spec/fixtures/java/annotations/Shop.java +++ b/spec/fixtures/java/annotations/Shop.java @@ -1,18 +1,26 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import io.realm.RealmList; import io.realm.RealmObject; -/* DO NOT EDIT | Generated by gyro */ - public class Shop extends RealmObject { - public interface Attributes { - String NAME = "name"; + public static final class Attributes { + public static final String NAME = "name"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String PRODUCTS = "products"; + public static final class Relationships { + public static final String PRODUCTS = "products"; + + private Relationships() { + // Hide constructor + } } private String name; @@ -27,12 +35,12 @@ public void setName(@android.support.annotation.NonNull final String name) { this.name = name; } - @android.support.annotation.Nullable + @android.support.annotation.NonNull public RealmList getProducts() { return products; } - public void setProducts(@android.support.annotation.Nullable final RealmList products) { + public void setProducts(@android.support.annotation.NonNull final RealmList products) { this.products = products; } } diff --git a/spec/fixtures/java/annotations/User.java b/spec/fixtures/java/annotations/User.java index 479e63c..ead0fe0 100644 --- a/spec/fixtures/java/annotations/User.java +++ b/spec/fixtures/java/annotations/User.java @@ -1,20 +1,28 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import java.util.Date; import io.realm.RealmObject; -/* DO NOT EDIT | Generated by gyro */ - public class User extends RealmObject { - public interface Attributes { - String BIRTHDAY = "birthday"; - String NAME = "name"; + public static final class Attributes { + public static final String BIRTHDAY = "birthday"; + public static final String NAME = "name"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String FIDELITY_CARD = "fidelityCard"; + public static final class Relationships { + public static final String FIDELITY_CARD = "fidelityCard"; + + private Relationships() { + // Hide constructor + } } private Date birthday; @@ -39,12 +47,12 @@ public void setName(@android.support.annotation.NonNull final String name) { this.name = name; } - @android.support.annotation.Nullable + @android.support.annotation.NonNull public FidelityCard getFidelityCard() { return fidelityCard; } - public void setFidelityCard(@android.support.annotation.Nullable final FidelityCard fidelityCard) { + public void setFidelityCard(@android.support.annotation.NonNull final FidelityCard fidelityCard) { this.fidelityCard = fidelityCard; } } diff --git a/spec/fixtures/java/enum/OptValue.java b/spec/fixtures/java/enum/OptValue.java index a8998b2..40650d7 100644 --- a/spec/fixtures/java/enum/OptValue.java +++ b/spec/fixtures/java/enum/OptValue.java @@ -4,9 +4,9 @@ public enum OptValue { - OPT_VALUE_ONE("opt_value_one"), - OPT_VALUE_TWO("opt_value_two"), - OPT_VALUE_THREE("opt_value_three"); + OPT_VALUE_ONE("OptValueOne"), + OPT_VALUE_TWO("OptValueTwo"), + OPT_VALUE_THREE("OptValueThree"); private final String jsonValue; diff --git a/spec/fixtures/java/enum/Shop.java b/spec/fixtures/java/enum/Shop.java index bbf516d..e37b9e7 100644 --- a/spec/fixtures/java/enum/Shop.java +++ b/spec/fixtures/java/enum/Shop.java @@ -1,24 +1,23 @@ package com.gyro.tests; -import io.realm.RealmObject; -import io.realm.annotations.Ignore; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class Shop extends RealmObject { - public interface Attributes { - String NAME = "name"; - String OPTIONAL_VALUE = "optionalValue"; - String TYPE = "type"; + public static final class Attributes { + public static final String NAME = "name"; + public static final String OPTIONAL_VALUE = "optionalValue"; + public static final String TYPE = "type"; + + private Attributes() { + // Hide constructor + } } private String name; - @Ignore - private OptValue optionalValueEnum; private String optionalValue; - @Ignore - private Type typeEnum; private String type; public String getName() { @@ -37,14 +36,6 @@ public void setOptionalValue(final String optionalValue) { this.optionalValue = optionalValue; } - public OptValue getOptionalValueEnum() { - return OptValue.get(getOptionalValue()); - } - - public void setOptionalValueEnum(final OptValue optionalValue) { - this.optionalValue = optionalValue.getJsonValue(); - } - public String getType() { return type; } @@ -53,6 +44,14 @@ public void setType(final String type) { this.type = type; } + public OptValue getOptionalValueEnum() { + return OptValue.get(getOptionalValue()); + } + + public void setOptionalValueEnum(final OptValue optionalValue) { + this.optionalValue = optionalValue.getJsonValue(); + } + public Type getTypeEnum() { return Type.get(getType()); } diff --git a/spec/fixtures/java/enum/Type.java b/spec/fixtures/java/enum/Type.java index 991b5f2..5632855 100644 --- a/spec/fixtures/java/enum/Type.java +++ b/spec/fixtures/java/enum/Type.java @@ -4,9 +4,9 @@ public enum Type { - TYPE_ONE("type_one"), - TYPE_TWO("type_two"), - TYPE_THREE("type_three"); + TYPE_ONE("TypeOne"), + TYPE_TWO("TypeTwo"), + TYPE_THREE("TypeThree"); private final String jsonValue; diff --git a/spec/fixtures/java/enum_json/Shop.java b/spec/fixtures/java/enum_json/Shop.java index 6ccffb1..26656df 100644 --- a/spec/fixtures/java/enum_json/Shop.java +++ b/spec/fixtures/java/enum_json/Shop.java @@ -1,27 +1,26 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import com.google.gson.annotations.SerializedName; import io.realm.RealmObject; -import io.realm.annotations.Ignore; - -/* DO NOT EDIT | Generated by gyro */ public class Shop extends RealmObject { - public interface Attributes { - String NAME = "name"; - String TYPE = "type"; - String TYPE_OPTIONAL = "typeOptional"; + public static final class Attributes { + public static final String NAME = "name"; + public static final String TYPE = "type"; + public static final String TYPE_OPTIONAL = "typeOptional"; + + private Attributes() { + // Hide constructor + } } private String name; - @Ignore - private Type typeEnum; @SerializedName("type") private String type; - @Ignore - private Type2 typeOptionalEnum; @SerializedName("type") private String typeOptional; @@ -41,14 +40,6 @@ public void setType(final String type) { this.type = type; } - public Type getTypeEnum() { - return Type.get(getType()); - } - - public void setTypeEnum(final Type type) { - this.type = type.getJsonValue(); - } - public String getTypeOptional() { return typeOptional; } @@ -57,6 +48,14 @@ public void setTypeOptional(final String typeOptional) { this.typeOptional = typeOptional; } + public Type getTypeEnum() { + return Type.get(getType()); + } + + public void setTypeEnum(final Type type) { + this.type = type.getJsonValue(); + } + public Type2 getTypeOptionalEnum() { return Type2.get(getTypeOptional()); } diff --git a/spec/fixtures/java/enum_json/Type2.java b/spec/fixtures/java/enum_json/Type2.java index 98e941e..2470098 100644 --- a/spec/fixtures/java/enum_json/Type2.java +++ b/spec/fixtures/java/enum_json/Type2.java @@ -4,9 +4,9 @@ public enum Type2 { - TYPE_ONE("json_type_one"), - TYPE_TWO("json_type_two"), - TYPE_THREE("json_type_three"); + TYPE2_ONE("json_type_one"), + TYPE2_TWO("json_type_two"), + TYPE2_THREE("json_type_three"); private final String jsonValue; diff --git a/spec/fixtures/java/enum_multi/FidelityCard.java b/spec/fixtures/java/enum_multi/FidelityCard.java index 276dffe..a75d107 100644 --- a/spec/fixtures/java/enum_multi/FidelityCard.java +++ b/spec/fixtures/java/enum_multi/FidelityCard.java @@ -1,18 +1,26 @@ package com.gyro.tests; -import io.realm.RealmObject; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class FidelityCard extends RealmObject { - public interface Attributes { - String IDENTIFIER = "identifier"; - String POINTS = "points"; + public static final class Attributes { + public static final String IDENTIFIER = "identifier"; + public static final String POINTS = "points"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String USER = "user"; + public static final class Relationships { + public static final String USER = "user"; + + private Relationships() { + // Hide constructor + } } private short identifier; diff --git a/spec/fixtures/java/enum_multi/Product.java b/spec/fixtures/java/enum_multi/Product.java index ae59a00..34dfe2f 100644 --- a/spec/fixtures/java/enum_multi/Product.java +++ b/spec/fixtures/java/enum_multi/Product.java @@ -1,28 +1,33 @@ package com.gyro.tests; -import io.realm.RealmObject; -import io.realm.annotations.Ignore; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class Product extends RealmObject { - public interface Attributes { - String BRAND = "brand"; - String NAME = "name"; - String PRICE = "price"; - String TYPE = "type"; + public static final class Attributes { + public static final String BRAND = "brand"; + public static final String NAME = "name"; + public static final String PRICE = "price"; + public static final String TYPE = "type"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String SHOP = "shop"; + public static final class Relationships { + public static final String SHOP = "shop"; + + private Relationships() { + // Hide constructor + } } private String brand; private String name; private int price; - @Ignore - private TypeA typeEnum; private String type; private Shop shop; @@ -58,14 +63,6 @@ public void setType(final String type) { this.type = type; } - public TypeA getTypeEnum() { - return TypeA.get(getType()); - } - - public void setTypeEnum(final TypeA type) { - this.type = type.getJsonValue(); - } - public Shop getShop() { return shop; } @@ -73,4 +70,12 @@ public Shop getShop() { public void setShop(final Shop shop) { this.shop = shop; } + + public TypeA getTypeEnum() { + return TypeA.get(getType()); + } + + public void setTypeEnum(final TypeA type) { + this.type = type.getJsonValue(); + } } diff --git a/spec/fixtures/java/enum_multi/Shop.java b/spec/fixtures/java/enum_multi/Shop.java index 2ccbcc0..1824468 100644 --- a/spec/fixtures/java/enum_multi/Shop.java +++ b/spec/fixtures/java/enum_multi/Shop.java @@ -1,25 +1,30 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import io.realm.RealmList; import io.realm.RealmObject; -import io.realm.annotations.Ignore; - -/* DO NOT EDIT | Generated by gyro */ public class Shop extends RealmObject { - public interface Attributes { - String NAME = "name"; - String TYPE = "type"; + public static final class Attributes { + public static final String NAME = "name"; + public static final String TYPE = "type"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String PRODUCTS = "products"; + public static final class Relationships { + public static final String PRODUCTS = "products"; + + private Relationships() { + // Hide constructor + } } private String name; - @Ignore - private TypeA typeEnum; private String type; private RealmList products; @@ -39,14 +44,6 @@ public void setType(final String type) { this.type = type; } - public TypeA getTypeEnum() { - return TypeA.get(getType()); - } - - public void setTypeEnum(final TypeA type) { - this.type = type.getJsonValue(); - } - public RealmList getProducts() { return products; } @@ -54,4 +51,12 @@ public RealmList getProducts() { public void setProducts(final RealmList products) { this.products = products; } + + public TypeA getTypeEnum() { + return TypeA.get(getType()); + } + + public void setTypeEnum(final TypeA type) { + this.type = type.getJsonValue(); + } } diff --git a/spec/fixtures/java/enum_multi/TypeA.java b/spec/fixtures/java/enum_multi/TypeA.java index bac59a0..458f4b0 100644 --- a/spec/fixtures/java/enum_multi/TypeA.java +++ b/spec/fixtures/java/enum_multi/TypeA.java @@ -4,9 +4,9 @@ public enum TypeA { - TYPE_ONE("type_a_one"), - TYPE_TWO("type_a_two"), - TYPE_THREE("type_a_three"); + TYPE_A_ONE("TypeAOne"), + TYPE_A_TWO("TypeATwo"), + TYPE_A_THREE("TypeAThree"); private final String jsonValue; diff --git a/spec/fixtures/java/enum_multi/TypeB.java b/spec/fixtures/java/enum_multi/TypeB.java index e62ae09..7bae8e7 100644 --- a/spec/fixtures/java/enum_multi/TypeB.java +++ b/spec/fixtures/java/enum_multi/TypeB.java @@ -4,9 +4,9 @@ public enum TypeB { - TYPE_ONE("type_b_one"), - TYPE_TWO("type_b_two"), - TYPE_THREE("type_b_three"); + TYPE_B_ONE("TypeBOne"), + TYPE_B_TWO("TypeBTwo"), + TYPE_B_THREE("TypeBThree"); private final String jsonValue; diff --git a/spec/fixtures/java/enum_multi/User.java b/spec/fixtures/java/enum_multi/User.java index 679840e..d53539d 100644 --- a/spec/fixtures/java/enum_multi/User.java +++ b/spec/fixtures/java/enum_multi/User.java @@ -1,28 +1,33 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import java.util.Date; import io.realm.RealmObject; -import io.realm.annotations.Ignore; - -/* DO NOT EDIT | Generated by gyro */ public class User extends RealmObject { - public interface Attributes { - String BIRTHDAY = "birthday"; - String NAME = "name"; - String TYPE = "type"; + public static final class Attributes { + public static final String BIRTHDAY = "birthday"; + public static final String NAME = "name"; + public static final String TYPE = "type"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String FIDELITY_CARD = "fidelityCard"; + public static final class Relationships { + public static final String FIDELITY_CARD = "fidelityCard"; + + private Relationships() { + // Hide constructor + } } private Date birthday; private String name; - @Ignore - private TypeB typeEnum; private String type; private FidelityCard fidelityCard; @@ -50,14 +55,6 @@ public void setType(final String type) { this.type = type; } - public TypeB getTypeEnum() { - return TypeB.get(getType()); - } - - public void setTypeEnum(final TypeB type) { - this.type = type.getJsonValue(); - } - public FidelityCard getFidelityCard() { return fidelityCard; } @@ -65,4 +62,12 @@ public FidelityCard getFidelityCard() { public void setFidelityCard(final FidelityCard fidelityCard) { this.fidelityCard = fidelityCard; } + + public TypeB getTypeEnum() { + return TypeB.get(getType()); + } + + public void setTypeEnum(final TypeB type) { + this.type = type.getJsonValue(); + } } diff --git a/spec/fixtures/java/ignored/Owner.java b/spec/fixtures/java/ignored/Owner.java index d3ef996..24c2445 100644 --- a/spec/fixtures/java/ignored/Owner.java +++ b/spec/fixtures/java/ignored/Owner.java @@ -1,18 +1,26 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import io.realm.RealmObject; import io.realm.annotations.Ignore; -/* DO NOT EDIT | Generated by gyro */ - public class Owner extends RealmObject { - public interface Attributes { - String NAME = "name"; + public static final class Attributes { + public static final String NAME = "name"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String SHOP = "shop"; + public static final class Relationships { + public static final String SHOP = "shop"; + + private Relationships() { + // Hide constructor + } } private String name; diff --git a/spec/fixtures/java/ignored/Product.java b/spec/fixtures/java/ignored/Product.java index c3d22e3..d5d33ad 100644 --- a/spec/fixtures/java/ignored/Product.java +++ b/spec/fixtures/java/ignored/Product.java @@ -1,13 +1,17 @@ package com.gyro.tests; -import io.realm.RealmObject; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class Product extends RealmObject { - public interface Relationships { - String SHOP = "shop"; + public static final class Relationships { + public static final String SHOP = "shop"; + + private Relationships() { + // Hide constructor + } } private Shop shop; diff --git a/spec/fixtures/java/ignored/Shop.java b/spec/fixtures/java/ignored/Shop.java index d31f203..c50f79d 100644 --- a/spec/fixtures/java/ignored/Shop.java +++ b/spec/fixtures/java/ignored/Shop.java @@ -1,24 +1,35 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import io.realm.RealmList; import io.realm.RealmObject; import io.realm.annotations.Ignore; -/* DO NOT EDIT | Generated by gyro */ - public class Shop extends RealmObject { - public interface Attributes { - String NAME = "name"; + public static final class Attributes { + public static final String NAME = "name"; + public static final String READ_ONLY = "readOnly"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String OWNER = "owner"; - String PRODUCTS = "products"; + public static final class Relationships { + public static final String OWNER = "owner"; + public static final String PRODUCTS = "products"; + + private Relationships() { + // Hide constructor + } } @Ignore private String ignored; + @Ignore + private String ignored2; private String name; private Owner owner; private RealmList products; @@ -31,6 +42,14 @@ public void setIgnored(final String ignored) { this.ignored = ignored; } + public String getIgnored2() { + return ignored2; + } + + public void setIgnored2(final String ignored2) { + this.ignored2 = ignored2; + } + public String getName() { return name; } @@ -39,7 +58,6 @@ public void setName(final String name) { this.name = name; } - public Owner getOwner() { return owner; } diff --git a/spec/fixtures/java/inverse/Dog.java b/spec/fixtures/java/inverse/Dog.java index 1d9c388..1fb66f2 100644 --- a/spec/fixtures/java/inverse/Dog.java +++ b/spec/fixtures/java/inverse/Dog.java @@ -1,14 +1,18 @@ package com.gyro.tests; -import io.realm.RealmObject; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class Dog extends RealmObject { - public interface Attributes { - String AGE = "age"; - String NAME = "name"; + public static final class Attributes { + public static final String AGE = "age"; + public static final String NAME = "name"; + + private Attributes() { + // Hide constructor + } } private short age; diff --git a/spec/fixtures/java/inverse/Person.java b/spec/fixtures/java/inverse/Person.java index 7bea7fd..df8ff28 100644 --- a/spec/fixtures/java/inverse/Person.java +++ b/spec/fixtures/java/inverse/Person.java @@ -1,14 +1,18 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import io.realm.RealmList; import io.realm.RealmObject; -/* DO NOT EDIT | Generated by gyro */ - public class Person extends RealmObject { - public interface Relationships { - String DOGS = "dogs"; + public static final class Relationships { + public static final String DOGS = "dogs"; + + private Relationships() { + // Hide constructor + } } private RealmList dogs; diff --git a/spec/fixtures/java/json/Product.java b/spec/fixtures/java/json/Product.java index c3d22e3..d5d33ad 100644 --- a/spec/fixtures/java/json/Product.java +++ b/spec/fixtures/java/json/Product.java @@ -1,13 +1,17 @@ package com.gyro.tests; -import io.realm.RealmObject; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class Product extends RealmObject { - public interface Relationships { - String SHOP = "shop"; + public static final class Relationships { + public static final String SHOP = "shop"; + + private Relationships() { + // Hide constructor + } } private Shop shop; diff --git a/spec/fixtures/java/json/Shop.java b/spec/fixtures/java/json/Shop.java index 8924f0a..4280a6d 100644 --- a/spec/fixtures/java/json/Shop.java +++ b/spec/fixtures/java/json/Shop.java @@ -1,20 +1,28 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import com.google.gson.annotations.SerializedName; import io.realm.RealmList; import io.realm.RealmObject; -/* DO NOT EDIT | Generated by gyro */ - public class Shop extends RealmObject { - public interface Attributes { - String NAME = "name"; + public static final class Attributes { + public static final String NAME = "name"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String PRODUCTS = "products"; + public static final class Relationships { + public static final String PRODUCTS = "products"; + + private Relationships() { + // Hide constructor + } } @SerializedName("json_name") diff --git a/spec/fixtures/java/no_value/Animal.java b/spec/fixtures/java/no_value/Animal.java index 742d9d3..c51617a 100644 --- a/spec/fixtures/java/no_value/Animal.java +++ b/spec/fixtures/java/no_value/Animal.java @@ -1,20 +1,28 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import java.util.List; import io.realm.RealmList; import io.realm.RealmObject; -/* DO NOT EDIT | Generated by gyro */ - public class Animal extends RealmObject { - public interface Attributes { - String ATTRIBUTE = "attribute"; + public static final class Attributes { + public static final String ATTRIBUTE = "attribute"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String RELATIONSHIP_NO_VALUE = "relationshipNoValue"; + public static final class Relationships { + public static final String RELATIONSHIP_NO_VALUE = "relationshipNoValue"; + + private Relationships() { + // Hide constructor + } } private String attribute; diff --git a/spec/fixtures/java/primary/FidelityCard.java b/spec/fixtures/java/primary/FidelityCard.java index acd183e..fea2ed8 100644 --- a/spec/fixtures/java/primary/FidelityCard.java +++ b/spec/fixtures/java/primary/FidelityCard.java @@ -1,19 +1,27 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import io.realm.RealmObject; import io.realm.annotations.PrimaryKey; -/* DO NOT EDIT | Generated by gyro */ - public class FidelityCard extends RealmObject { - public interface Attributes { - String IDENTIFIER = "identifier"; - String POINTS = "points"; + public static final class Attributes { + public static final String IDENTIFIER = "identifier"; + public static final String POINTS = "points"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String USER = "user"; + public static final class Relationships { + public static final String USER = "user"; + + private Relationships() { + // Hide constructor + } } @PrimaryKey diff --git a/spec/fixtures/java/primary/Product.java b/spec/fixtures/java/primary/Product.java index cbdd4e2..4df401a 100644 --- a/spec/fixtures/java/primary/Product.java +++ b/spec/fixtures/java/primary/Product.java @@ -1,16 +1,20 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import io.realm.RealmObject; import io.realm.annotations.PrimaryKey; -/* DO NOT EDIT | Generated by gyro */ - public class Product extends RealmObject { - public interface Attributes { - String BRAND = "brand"; - String NAME = "name"; - String PRICE = "price"; + public static final class Attributes { + public static final String BRAND = "brand"; + public static final String NAME = "name"; + public static final String PRICE = "price"; + + private Attributes() { + // Hide constructor + } } private String brand; diff --git a/spec/fixtures/java/primary/Shop.java b/spec/fixtures/java/primary/Shop.java index 7a04f99..64c324c 100644 --- a/spec/fixtures/java/primary/Shop.java +++ b/spec/fixtures/java/primary/Shop.java @@ -1,19 +1,27 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import io.realm.RealmList; import io.realm.RealmObject; import io.realm.annotations.PrimaryKey; -/* DO NOT EDIT | Generated by gyro */ - public class Shop extends RealmObject { - public interface Attributes { - String NAME = "name"; + public static final class Attributes { + public static final String NAME = "name"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String PRODUCTS = "products"; + public static final class Relationships { + public static final String PRODUCTS = "products"; + + private Relationships() { + // Hide constructor + } } @PrimaryKey diff --git a/spec/fixtures/java/primary/User.java b/spec/fixtures/java/primary/User.java index 3c7155d..51bdc4b 100644 --- a/spec/fixtures/java/primary/User.java +++ b/spec/fixtures/java/primary/User.java @@ -1,21 +1,29 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import java.util.Date; import io.realm.RealmObject; import io.realm.annotations.PrimaryKey; -/* DO NOT EDIT | Generated by gyro */ - public class User extends RealmObject { - public interface Attributes { - String BIRTHDAY = "birthday"; - String NAME = "name"; + public static final class Attributes { + public static final String BIRTHDAY = "birthday"; + public static final String NAME = "name"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String FIDELITY_CARD = "fidelityCard"; + public static final class Relationships { + public static final String FIDELITY_CARD = "fidelityCard"; + + private Relationships() { + // Hide constructor + } } private Date birthday; diff --git a/spec/fixtures/java/realm/FidelityCard.java b/spec/fixtures/java/realm/FidelityCard.java index 276dffe..a75d107 100644 --- a/spec/fixtures/java/realm/FidelityCard.java +++ b/spec/fixtures/java/realm/FidelityCard.java @@ -1,18 +1,26 @@ package com.gyro.tests; -import io.realm.RealmObject; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class FidelityCard extends RealmObject { - public interface Attributes { - String IDENTIFIER = "identifier"; - String POINTS = "points"; + public static final class Attributes { + public static final String IDENTIFIER = "identifier"; + public static final String POINTS = "points"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String USER = "user"; + public static final class Relationships { + public static final String USER = "user"; + + private Relationships() { + // Hide constructor + } } private short identifier; diff --git a/spec/fixtures/java/realm/Product.java b/spec/fixtures/java/realm/Product.java index 69bda60..b54352e 100644 --- a/spec/fixtures/java/realm/Product.java +++ b/spec/fixtures/java/realm/Product.java @@ -1,15 +1,19 @@ package com.gyro.tests; -import io.realm.RealmObject; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class Product extends RealmObject { - public interface Attributes { - String BRAND = "brand"; - String NAME = "name"; - String PRICE = "price"; + public static final class Attributes { + public static final String BRAND = "brand"; + public static final String NAME = "name"; + public static final String PRICE = "price"; + + private Attributes() { + // Hide constructor + } } private String brand; diff --git a/spec/fixtures/java/realm/Shop.java b/spec/fixtures/java/realm/Shop.java index fecd497..8912994 100644 --- a/spec/fixtures/java/realm/Shop.java +++ b/spec/fixtures/java/realm/Shop.java @@ -1,18 +1,26 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import io.realm.RealmList; import io.realm.RealmObject; -/* DO NOT EDIT | Generated by gyro */ - public class Shop extends RealmObject { - public interface Attributes { - String NAME = "name"; + public static final class Attributes { + public static final String NAME = "name"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String PRODUCTS = "products"; + public static final class Relationships { + public static final String PRODUCTS = "products"; + + private Relationships() { + // Hide constructor + } } private String name; diff --git a/spec/fixtures/java/realm/User.java b/spec/fixtures/java/realm/User.java index b663569..39cd6c5 100644 --- a/spec/fixtures/java/realm/User.java +++ b/spec/fixtures/java/realm/User.java @@ -1,20 +1,28 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import java.util.Date; import io.realm.RealmObject; -/* DO NOT EDIT | Generated by gyro */ - public class User extends RealmObject { - public interface Attributes { - String BIRTHDAY = "birthday"; - String NAME = "name"; + public static final class Attributes { + public static final String BIRTHDAY = "birthday"; + public static final String NAME = "name"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String FIDELITY_CARD = "fidelityCard"; + public static final class Relationships { + public static final String FIDELITY_CARD = "fidelityCard"; + + private Relationships() { + // Hide constructor + } } private Date birthday; diff --git a/spec/fixtures/java/wrappers/FidelityCard.java b/spec/fixtures/java/wrappers/FidelityCard.java index 4c34369..14a5fef 100644 --- a/spec/fixtures/java/wrappers/FidelityCard.java +++ b/spec/fixtures/java/wrappers/FidelityCard.java @@ -1,22 +1,29 @@ package com.gyro.tests; -import io.realm.RealmObject; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class FidelityCard extends RealmObject { - public interface Attributes { - String IDENTIFIER = "identifier"; - String POINTS = "points"; + public static final class Attributes { + public static final String IDENTIFIER = "identifier"; + public static final String POINTS = "points"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String USER = "user"; + public static final class Relationships { + public static final String USER = "user"; + + private Relationships() { + // Hide constructor + } } private short identifier; - @android.support.annotation.IntRange(from=0,to=255) private Integer points; private User user; @@ -28,12 +35,11 @@ public void setIdentifier(final short identifier) { this.identifier = identifier; } - @android.support.annotation.IntRange(from=0,to=255) public Integer getPoints() { return points; } - public void setPoints(@android.support.annotation.IntRange(from=0,to=255) final Integer points) { + public void setPoints(final Integer points) { this.points = points; } diff --git a/spec/fixtures/java/wrappers/Product.java b/spec/fixtures/java/wrappers/Product.java index ea11ad1..e737e23 100644 --- a/spec/fixtures/java/wrappers/Product.java +++ b/spec/fixtures/java/wrappers/Product.java @@ -1,15 +1,19 @@ package com.gyro.tests; -import io.realm.RealmObject; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class Product extends RealmObject { - public interface Attributes { - String BRAND = "brand"; - String NAME = "name"; - String PRICE = "price"; + public static final class Attributes { + public static final String BRAND = "brand"; + public static final String NAME = "name"; + public static final String PRICE = "price"; + + private Attributes() { + // Hide constructor + } } private String brand; diff --git a/spec/fixtures/java/wrappers/Shop.java b/spec/fixtures/java/wrappers/Shop.java index fecd497..8912994 100644 --- a/spec/fixtures/java/wrappers/Shop.java +++ b/spec/fixtures/java/wrappers/Shop.java @@ -1,18 +1,26 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import io.realm.RealmList; import io.realm.RealmObject; -/* DO NOT EDIT | Generated by gyro */ - public class Shop extends RealmObject { - public interface Attributes { - String NAME = "name"; + public static final class Attributes { + public static final String NAME = "name"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String PRODUCTS = "products"; + public static final class Relationships { + public static final String PRODUCTS = "products"; + + private Relationships() { + // Hide constructor + } } private String name; diff --git a/spec/fixtures/java/wrappers/User.java b/spec/fixtures/java/wrappers/User.java index b663569..39cd6c5 100644 --- a/spec/fixtures/java/wrappers/User.java +++ b/spec/fixtures/java/wrappers/User.java @@ -1,20 +1,28 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import java.util.Date; import io.realm.RealmObject; -/* DO NOT EDIT | Generated by gyro */ - public class User extends RealmObject { - public interface Attributes { - String BIRTHDAY = "birthday"; - String NAME = "name"; + public static final class Attributes { + public static final String BIRTHDAY = "birthday"; + public static final String NAME = "name"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String FIDELITY_CARD = "fidelityCard"; + public static final class Relationships { + public static final String FIDELITY_CARD = "fidelityCard"; + + private Relationships() { + // Hide constructor + } } private Date birthday; diff --git a/spec/fixtures/java/wrappers_annotations/FidelityCard.java b/spec/fixtures/java/wrappers_annotations/FidelityCard.java index 196e1a2..0501552 100644 --- a/spec/fixtures/java/wrappers_annotations/FidelityCard.java +++ b/spec/fixtures/java/wrappers_annotations/FidelityCard.java @@ -1,18 +1,26 @@ package com.gyro.tests; -import io.realm.RealmObject; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class FidelityCard extends RealmObject { - public interface Attributes { - String IDENTIFIER = "identifier"; - String POINTS = "points"; + public static final class Attributes { + public static final String IDENTIFIER = "identifier"; + public static final String POINTS = "points"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String USER = "user"; + public static final class Relationships { + public static final String USER = "user"; + + private Relationships() { + // Hide constructor + } } private short identifier; @@ -38,12 +46,12 @@ public void setPoints(@android.support.annotation.Nullable @android.support.anno this.points = points; } - @android.support.annotation.Nullable + @android.support.annotation.NonNull public User getUser() { return user; } - public void setUser(@android.support.annotation.Nullable final User user) { + public void setUser(@android.support.annotation.NonNull final User user) { this.user = user; } } diff --git a/spec/fixtures/java/wrappers_annotations/Product.java b/spec/fixtures/java/wrappers_annotations/Product.java index dd74bf9..eba5241 100644 --- a/spec/fixtures/java/wrappers_annotations/Product.java +++ b/spec/fixtures/java/wrappers_annotations/Product.java @@ -1,15 +1,19 @@ package com.gyro.tests; -import io.realm.RealmObject; - /* DO NOT EDIT | Generated by gyro */ +import io.realm.RealmObject; + public class Product extends RealmObject { - public interface Attributes { - String BRAND = "brand"; - String NAME = "name"; - String PRICE = "price"; + public static final class Attributes { + public static final String BRAND = "brand"; + public static final String NAME = "name"; + public static final String PRICE = "price"; + + private Attributes() { + // Hide constructor + } } private String brand; diff --git a/spec/fixtures/java/wrappers_annotations/Shop.java b/spec/fixtures/java/wrappers_annotations/Shop.java index dd12a2b..440cf2f 100644 --- a/spec/fixtures/java/wrappers_annotations/Shop.java +++ b/spec/fixtures/java/wrappers_annotations/Shop.java @@ -1,18 +1,26 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import io.realm.RealmList; import io.realm.RealmObject; -/* DO NOT EDIT | Generated by gyro */ - public class Shop extends RealmObject { - public interface Attributes { - String NAME = "name"; + public static final class Attributes { + public static final String NAME = "name"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String PRODUCTS = "products"; + public static final class Relationships { + public static final String PRODUCTS = "products"; + + private Relationships() { + // Hide constructor + } } private String name; @@ -27,12 +35,12 @@ public void setName(@android.support.annotation.NonNull final String name) { this.name = name; } - @android.support.annotation.Nullable + @android.support.annotation.NonNull public RealmList getProducts() { return products; } - public void setProducts(@android.support.annotation.Nullable final RealmList products) { + public void setProducts(@android.support.annotation.NonNull final RealmList products) { this.products = products; } } diff --git a/spec/fixtures/java/wrappers_annotations/User.java b/spec/fixtures/java/wrappers_annotations/User.java index 479e63c..ead0fe0 100644 --- a/spec/fixtures/java/wrappers_annotations/User.java +++ b/spec/fixtures/java/wrappers_annotations/User.java @@ -1,20 +1,28 @@ package com.gyro.tests; +/* DO NOT EDIT | Generated by gyro */ + import java.util.Date; import io.realm.RealmObject; -/* DO NOT EDIT | Generated by gyro */ - public class User extends RealmObject { - public interface Attributes { - String BIRTHDAY = "birthday"; - String NAME = "name"; + public static final class Attributes { + public static final String BIRTHDAY = "birthday"; + public static final String NAME = "name"; + + private Attributes() { + // Hide constructor + } } - public interface Relationships { - String FIDELITY_CARD = "fidelityCard"; + public static final class Relationships { + public static final String FIDELITY_CARD = "fidelityCard"; + + private Relationships() { + // Hide constructor + } } private Date birthday; @@ -39,12 +47,12 @@ public void setName(@android.support.annotation.NonNull final String name) { this.name = name; } - @android.support.annotation.Nullable + @android.support.annotation.NonNull public FidelityCard getFidelityCard() { return fidelityCard; } - public void setFidelityCard(@android.support.annotation.Nullable final FidelityCard fidelityCard) { + public void setFidelityCard(@android.support.annotation.NonNull final FidelityCard fidelityCard) { this.fidelityCard = fidelityCard; } } diff --git a/spec/fixtures/objc/bool/JSON/RLMShop+JSON.h b/spec/fixtures/objc/bool/JSON/RLMShop+JSON.h deleted file mode 100644 index d410b9f..0000000 --- a/spec/fixtures/objc/bool/JSON/RLMShop+JSON.h +++ /dev/null @@ -1,16 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMShop.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop (JSON) - -@end diff --git a/spec/fixtures/objc/bool/JSON/RLMShop+JSON.m b/spec/fixtures/objc/bool/JSON/RLMShop+JSON.m deleted file mode 100644 index 0c3f418..0000000 --- a/spec/fixtures/objc/bool/JSON/RLMShop+JSON.m +++ /dev/null @@ -1,59 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop+JSON.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop (JSON) - -+ (NSDictionary *)JSONInboundMappingDictionary -{ - return @{ - @"isOpened" : @"isOpened", - @"isValid" : @"isValid", - @"name" : @"name" - }; -} - -+ (NSDictionary *)JSONOutboundMappingDictionary -{ - return @{ - @"isOpened" : @"isOpened", - @"isValid" : @"isValid", - @"name" : @"name" - }; -} - -+ (NSValueTransformer *)isOpenedJSONTransformer -{ - return [MCJSONValueTransformer valueTransformerWithMappingDictionary:@{ - @"null" : @(NO), - [NSNull null] : @(NO), - @"" : @(NO), - @"false" : @(NO), - @"true" : @(YES), - @(NO) : @(NO), - @(YES) : @(YES) - }]; -} - -+ (NSValueTransformer *)isValidJSONTransformer -{ - return [MCJSONValueTransformer valueTransformerWithMappingDictionary:@{ - @"null" : @(NO), - [NSNull null] : @(NO), - @"" : @(NO), - @"false" : @(NO), - @"true" : @(YES), - @(NO) : @(NO), - @(YES) : @(YES) - }]; -} - -@end diff --git a/spec/fixtures/objc/bool/RLMShop.h b/spec/fixtures/objc/bool/RLMShop.h deleted file mode 100644 index 941e770..0000000 --- a/spec/fixtures/objc/bool/RLMShop.h +++ /dev/null @@ -1,29 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Defines & Constants - -extern const struct RLMShopAttributes { - __unsafe_unretained NSString *isOpened; - __unsafe_unretained NSString *isValid; - __unsafe_unretained NSString *name; -} RLMShopAttributes; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop : RLMObject - -#pragma mark - Properties - -@property BOOL isOpened; -@property BOOL isValid; -@property NSString *name; - -@end diff --git a/spec/fixtures/objc/bool/RLMShop.m b/spec/fixtures/objc/bool/RLMShop.m deleted file mode 100644 index 751f653..0000000 --- a/spec/fixtures/objc/bool/RLMShop.m +++ /dev/null @@ -1,37 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop.h" - -#pragma mark - Defines & Constants - -const struct RLMShopAttributes RLMShopAttributes = { - .isOpened = @"isOpened", - .isValid = @"isValid", - .name = @"name" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"isOpened", @"isValid", @"name"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"isOpened" : @(NO), @"isValid" : @(0), @"name" : @""}; -} - -@end diff --git a/spec/fixtures/objc/enum/RLMShop.h b/spec/fixtures/objc/enum/RLMShop.h deleted file mode 100644 index 71e28dd..0000000 --- a/spec/fixtures/objc/enum/RLMShop.h +++ /dev/null @@ -1,30 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMTypes.h" - -#pragma mark - Defines & Constants - -extern const struct RLMShopAttributes { - __unsafe_unretained NSString *name; - __unsafe_unretained NSString *optionalValue; - __unsafe_unretained NSString *type; -} RLMShopAttributes; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop : RLMObject - -#pragma mark - Properties - -@property NSString *name; -@property OptValue optionalValue; -@property RLMType type; - -@end diff --git a/spec/fixtures/objc/enum/RLMShop.m b/spec/fixtures/objc/enum/RLMShop.m deleted file mode 100644 index 2c2203a..0000000 --- a/spec/fixtures/objc/enum/RLMShop.m +++ /dev/null @@ -1,37 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop.h" - -#pragma mark - Defines & Constants - -const struct RLMShopAttributes RLMShopAttributes = { - .name = @"name", - .optionalValue = @"optionalValue", - .type = @"type" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"name", @"type"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"name" : @"", @"type" : @(0)}; -} - -@end diff --git a/spec/fixtures/objc/enum/RLMTypes.h b/spec/fixtures/objc/enum/RLMTypes.h deleted file mode 100644 index 07b9515..0000000 --- a/spec/fixtures/objc/enum/RLMTypes.h +++ /dev/null @@ -1,18 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Types - -typedef NS_ENUM(int, OptValue) { - OptValueNone = 0, - OptValueOne, - OptValueTwo, - OptValueThree -}; - -typedef NS_ENUM(int, RLMType) { - RLMTypeOne = 0, - RLMTypeTwo, - RLMTypeThree -}; diff --git a/spec/fixtures/objc/enum_json/JSON/RLMShop+JSON.h b/spec/fixtures/objc/enum_json/JSON/RLMShop+JSON.h deleted file mode 100644 index d410b9f..0000000 --- a/spec/fixtures/objc/enum_json/JSON/RLMShop+JSON.h +++ /dev/null @@ -1,16 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMShop.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop (JSON) - -@end diff --git a/spec/fixtures/objc/enum_json/JSON/RLMShop+JSON.m b/spec/fixtures/objc/enum_json/JSON/RLMShop+JSON.m deleted file mode 100644 index 4d8022b..0000000 --- a/spec/fixtures/objc/enum_json/JSON/RLMShop+JSON.m +++ /dev/null @@ -1,60 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop+JSON.h" -#import "RLMTypes.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop (JSON) - -+ (NSDictionary *)JSONInboundMappingDictionary -{ - return @{ - @"name" : @"name", - @"type" : @"type", - @"type" : @"typeOptional" - }; -} - -+ (NSDictionary *)JSONOutboundMappingDictionary -{ - return @{ - @"name" : @"name", - @"type" : @"type", - @"typeOptional" : @"type" - }; -} - -+ (NSValueTransformer *)typeJSONTransformer -{ - return [MCJSONValueTransformer valueTransformerWithMappingDictionary:@{ - @"null" : @(RLMTypeOne), - [NSNull null] : @(RLMTypeOne), - @"" : @(RLMTypeOne), - @"" : @(RLMTypeOne), - @"json_type_one" : @(RLMTypeOne), - @"json_type_two" : @(RLMTypeTwo), - @"json_type_three" : @(RLMTypeThree) - }]; -} - -+ (NSValueTransformer *)typeOptionalJSONTransformer -{ - return [MCJSONValueTransformer valueTransformerWithMappingDictionary:@{ - @"null" : @(RLMType2None), - [NSNull null] : @(RLMType2None), - @"" : @(RLMType2None), - @"" : @(RLMType2None), - @"json_type_one" : @(RLMType2One), - @"json_type_two" : @(RLMType2Two), - @"json_type_three" : @(RLMType2Three) - }]; -} - -@end diff --git a/spec/fixtures/objc/enum_json/RLMShop.h b/spec/fixtures/objc/enum_json/RLMShop.h deleted file mode 100644 index 7761364..0000000 --- a/spec/fixtures/objc/enum_json/RLMShop.h +++ /dev/null @@ -1,30 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMTypes.h" - -#pragma mark - Defines & Constants - -extern const struct RLMShopAttributes { - __unsafe_unretained NSString *name; - __unsafe_unretained NSString *type; - __unsafe_unretained NSString *typeOptional; -} RLMShopAttributes; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop : RLMObject - -#pragma mark - Properties - -@property NSString *name; -@property RLMType type; -@property RLMType2 typeOptional; - -@end diff --git a/spec/fixtures/objc/enum_json/RLMShop.m b/spec/fixtures/objc/enum_json/RLMShop.m deleted file mode 100644 index 79ddb51..0000000 --- a/spec/fixtures/objc/enum_json/RLMShop.m +++ /dev/null @@ -1,37 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop.h" - -#pragma mark - Defines & Constants - -const struct RLMShopAttributes RLMShopAttributes = { - .name = @"name", - .type = @"type", - .typeOptional = @"typeOptional" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"name", @"type"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"name" : @"", @"type" : @(0)}; -} - -@end diff --git a/spec/fixtures/objc/enum_json/RLMTypes.h b/spec/fixtures/objc/enum_json/RLMTypes.h deleted file mode 100644 index 73e90f4..0000000 --- a/spec/fixtures/objc/enum_json/RLMTypes.h +++ /dev/null @@ -1,18 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Types - -typedef NS_ENUM(int, RLMType) { - RLMTypeOne = 0, - RLMTypeTwo, - RLMTypeThree -}; - -typedef NS_ENUM(int, RLMType2) { - RLMType2None = 0, - RLMType2One, - RLMType2Two, - RLMType2Three -}; diff --git a/spec/fixtures/objc/enum_multi/RLMFidelityCard.h b/spec/fixtures/objc/enum_multi/RLMFidelityCard.h deleted file mode 100644 index 630841a..0000000 --- a/spec/fixtures/objc/enum_multi/RLMFidelityCard.h +++ /dev/null @@ -1,36 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Types - -@class RLMUser; - -#pragma mark - Defines & Constants - -extern const struct RLMFidelityCardAttributes { - __unsafe_unretained NSString *identifier; - __unsafe_unretained NSString *points; -} RLMFidelityCardAttributes; - -extern const struct RLMFidelityCardRelationships { - __unsafe_unretained NSString *user; -} RLMFidelityCardRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMFidelityCard : RLMObject - -#pragma mark - Properties - -@property int identifier; -@property long points; -@property RLMUser *user; - -@end diff --git a/spec/fixtures/objc/enum_multi/RLMFidelityCard.m b/spec/fixtures/objc/enum_multi/RLMFidelityCard.m deleted file mode 100644 index 404bf64..0000000 --- a/spec/fixtures/objc/enum_multi/RLMFidelityCard.m +++ /dev/null @@ -1,40 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMFidelityCard.h" - -#pragma mark - Defines & Constants - -const struct RLMFidelityCardAttributes RLMFidelityCardAttributes = { - .identifier = @"identifier", - .points = @"points" -}; - -const struct RLMFidelityCardRelationships RLMFidelityCardRelationships = { - .user = @"user" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMFidelityCard - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"identifier", @"points"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"identifier" : @(0), @"points" : @(0)}; -} - -@end diff --git a/spec/fixtures/objc/enum_multi/RLMProduct.h b/spec/fixtures/objc/enum_multi/RLMProduct.h deleted file mode 100644 index bc774a1..0000000 --- a/spec/fixtures/objc/enum_multi/RLMProduct.h +++ /dev/null @@ -1,41 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMTypes.h" - -#pragma mark - Types - -@class RLMShop; - -#pragma mark - Defines & Constants - -extern const struct RLMProductAttributes { - __unsafe_unretained NSString *brand; - __unsafe_unretained NSString *name; - __unsafe_unretained NSString *price; - __unsafe_unretained NSString *type; -} RLMProductAttributes; - -extern const struct RLMProductRelationships { - __unsafe_unretained NSString *shop; -} RLMProductRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMProduct : RLMObject - -#pragma mark - Properties - -@property NSString *brand; -@property NSString *name; -@property long price; -@property RLMTypeA type; -@property RLMShop *shop; - -@end diff --git a/spec/fixtures/objc/enum_multi/RLMProduct.m b/spec/fixtures/objc/enum_multi/RLMProduct.m deleted file mode 100644 index 6089c0d..0000000 --- a/spec/fixtures/objc/enum_multi/RLMProduct.m +++ /dev/null @@ -1,42 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMProduct.h" - -#pragma mark - Defines & Constants - -const struct RLMProductAttributes RLMProductAttributes = { - .brand = @"brand", - .name = @"name", - .price = @"price", - .type = @"type" -}; - -const struct RLMProductRelationships RLMProductRelationships = { - .shop = @"shop" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMProduct - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"brand", @"name", @"price", @"type"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"brand" : @"", @"name" : @"", @"price" : @(0), @"type" : @(0)}; -} - -@end diff --git a/spec/fixtures/objc/enum_multi/RLMProtocols.h b/spec/fixtures/objc/enum_multi/RLMProtocols.h deleted file mode 100644 index 0836b24..0000000 --- a/spec/fixtures/objc/enum_multi/RLMProtocols.h +++ /dev/null @@ -1,8 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Protocols - -// This protocol enables typed collections. i.e.: RLMArray -RLM_ARRAY_TYPE(RLMProduct) diff --git a/spec/fixtures/objc/enum_multi/RLMShop.h b/spec/fixtures/objc/enum_multi/RLMShop.h deleted file mode 100644 index 55f312c..0000000 --- a/spec/fixtures/objc/enum_multi/RLMShop.h +++ /dev/null @@ -1,38 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMTypes.h" -#import "RLMProtocols.h" - -#pragma mark - Types - -@class RLMProduct; - -#pragma mark - Defines & Constants - -extern const struct RLMShopAttributes { - __unsafe_unretained NSString *name; - __unsafe_unretained NSString *type; -} RLMShopAttributes; - -extern const struct RLMShopRelationships { - __unsafe_unretained NSString *products; -} RLMShopRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop : RLMObject - -#pragma mark - Properties - -@property NSString *name; -@property RLMTypeA type; -@property RLMArray *products; - -@end diff --git a/spec/fixtures/objc/enum_multi/RLMShop.m b/spec/fixtures/objc/enum_multi/RLMShop.m deleted file mode 100644 index d288774..0000000 --- a/spec/fixtures/objc/enum_multi/RLMShop.m +++ /dev/null @@ -1,40 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop.h" - -#pragma mark - Defines & Constants - -const struct RLMShopAttributes RLMShopAttributes = { - .name = @"name", - .type = @"type" -}; - -const struct RLMShopRelationships RLMShopRelationships = { - .products = @"products" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"name", @"type"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"name" : @"", @"type" : @(0)}; -} - -@end diff --git a/spec/fixtures/objc/enum_multi/RLMTypes.h b/spec/fixtures/objc/enum_multi/RLMTypes.h deleted file mode 100644 index 50d57c8..0000000 --- a/spec/fixtures/objc/enum_multi/RLMTypes.h +++ /dev/null @@ -1,17 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Types - -typedef NS_ENUM(int, RLMTypeA) { - RLMTypeAOne = 0, - RLMTypeATwo, - RLMTypeAThree -}; - -typedef NS_ENUM(int, RLMTypeB) { - RLMTypeBOne = 0, - RLMTypeBTwo, - RLMTypeBThree -}; diff --git a/spec/fixtures/objc/enum_multi/RLMUser.h b/spec/fixtures/objc/enum_multi/RLMUser.h deleted file mode 100644 index 4ffdda3..0000000 --- a/spec/fixtures/objc/enum_multi/RLMUser.h +++ /dev/null @@ -1,39 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMTypes.h" - -#pragma mark - Types - -@class RLMFidelityCard; - -#pragma mark - Defines & Constants - -extern const struct RLMUserAttributes { - __unsafe_unretained NSString *birthday; - __unsafe_unretained NSString *name; - __unsafe_unretained NSString *type; -} RLMUserAttributes; - -extern const struct RLMUserRelationships { - __unsafe_unretained NSString *fidelityCard; -} RLMUserRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMUser : RLMObject - -#pragma mark - Properties - -@property NSDate *birthday; -@property NSString *name; -@property RLMTypeB type; -@property RLMFidelityCard *fidelityCard; - -@end diff --git a/spec/fixtures/objc/enum_multi/RLMUser.m b/spec/fixtures/objc/enum_multi/RLMUser.m deleted file mode 100644 index d95ac99..0000000 --- a/spec/fixtures/objc/enum_multi/RLMUser.m +++ /dev/null @@ -1,41 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMUser.h" - -#pragma mark - Defines & Constants - -const struct RLMUserAttributes RLMUserAttributes = { - .birthday = @"birthday", - .name = @"name", - .type = @"type" -}; - -const struct RLMUserRelationships RLMUserRelationships = { - .fidelityCard = @"fidelityCard" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMUser - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"birthday", @"name", @"type"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"birthday" : [NSDate date], @"name" : @"", @"type" : @(0)}; -} - -@end diff --git a/spec/fixtures/objc/ignored/RLMOwner.h b/spec/fixtures/objc/ignored/RLMOwner.h deleted file mode 100644 index 520eaf0..0000000 --- a/spec/fixtures/objc/ignored/RLMOwner.h +++ /dev/null @@ -1,34 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Types - -@class RLMShop; - -#pragma mark - Defines & Constants - -extern const struct RLMOwnerAttributes { - __unsafe_unretained NSString *name; -} RLMOwnerAttributes; - -extern const struct RLMOwnerRelationships { - __unsafe_unretained NSString *shop; -} RLMOwnerRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMOwner : RLMObject - -#pragma mark - Properties - -@property NSString *name; -@property RLMShop *shop; - -@end diff --git a/spec/fixtures/objc/ignored/RLMOwner.m b/spec/fixtures/objc/ignored/RLMOwner.m deleted file mode 100644 index 7e2c638..0000000 --- a/spec/fixtures/objc/ignored/RLMOwner.m +++ /dev/null @@ -1,33 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMOwner.h" - -#pragma mark - Defines & Constants - -const struct RLMOwnerAttributes RLMOwnerAttributes = { - .name = @"name" -}; - -const struct RLMOwnerRelationships RLMOwnerRelationships = { - .shop = @"shop" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMOwner - -#pragma mark - Superclass Overrides - -// Specify properties to ignore (Realm won't persist these) -+ (NSArray *)ignoredProperties -{ - return @[@"shop"]; -} - -@end diff --git a/spec/fixtures/objc/ignored/RLMProduct.h b/spec/fixtures/objc/ignored/RLMProduct.h deleted file mode 100644 index 441d9a3..0000000 --- a/spec/fixtures/objc/ignored/RLMProduct.h +++ /dev/null @@ -1,29 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Types - -@class RLMShop; - -#pragma mark - Defines & Constants - -extern const struct RLMProductRelationships { - __unsafe_unretained NSString *shop; -} RLMProductRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMProduct : RLMObject - -#pragma mark - Properties - -@property RLMShop *shop; - -@end diff --git a/spec/fixtures/objc/ignored/RLMProduct.m b/spec/fixtures/objc/ignored/RLMProduct.m deleted file mode 100644 index 0cb4666..0000000 --- a/spec/fixtures/objc/ignored/RLMProduct.m +++ /dev/null @@ -1,21 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMProduct.h" - -#pragma mark - Defines & Constants - -const struct RLMProductRelationships RLMProductRelationships = { - .shop = @"shop" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMProduct - -@end diff --git a/spec/fixtures/objc/ignored/RLMProtocols.h b/spec/fixtures/objc/ignored/RLMProtocols.h deleted file mode 100644 index 0836b24..0000000 --- a/spec/fixtures/objc/ignored/RLMProtocols.h +++ /dev/null @@ -1,8 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Protocols - -// This protocol enables typed collections. i.e.: RLMArray -RLM_ARRAY_TYPE(RLMProduct) diff --git a/spec/fixtures/objc/ignored/RLMShop.h b/spec/fixtures/objc/ignored/RLMShop.h deleted file mode 100644 index bd7695f..0000000 --- a/spec/fixtures/objc/ignored/RLMShop.h +++ /dev/null @@ -1,42 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMProtocols.h" - -#pragma mark - Types - -@class RLMOwner; -@class RLMProduct; - -#pragma mark - Defines & Constants - -extern const struct RLMShopAttributes { - __unsafe_unretained NSString *ignored; - __unsafe_unretained NSString *name; - __unsafe_unretained NSString *readOnly; -} RLMShopAttributes; - -extern const struct RLMShopRelationships { - __unsafe_unretained NSString *owner; - __unsafe_unretained NSString *products; -} RLMShopRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop : RLMObject - -#pragma mark - Properties - -@property NSString *ignored; -@property NSString *name; -@property (readonly) NSString *readOnly; -@property RLMOwner *owner; -@property RLMArray *products; - -@end diff --git a/spec/fixtures/objc/ignored/RLMShop.m b/spec/fixtures/objc/ignored/RLMShop.m deleted file mode 100644 index 11ad2c1..0000000 --- a/spec/fixtures/objc/ignored/RLMShop.m +++ /dev/null @@ -1,53 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop.h" - -#pragma mark - Defines & Constants - -const struct RLMShopAttributes RLMShopAttributes = { - .ignored = @"ignored", - .name = @"name", - .readOnly = @"readOnly" -}; - -const struct RLMShopRelationships RLMShopRelationships = { - .owner = @"owner", - .products = @"products" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"ignored", @"name", @"readOnly"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"ignored" : @"", @"name" : @"", @"readOnly" : @""}; -} - -// Specify properties to ignore (Realm won't persist these) -+ (NSArray *)ignoredProperties -{ - return @[@"ignored"]; -} - -- (NSString *)readOnly -{ - return self.name; -} - -@end diff --git a/spec/fixtures/objc/inverse/RLMDog.h b/spec/fixtures/objc/inverse/RLMDog.h deleted file mode 100644 index 854c6df..0000000 --- a/spec/fixtures/objc/inverse/RLMDog.h +++ /dev/null @@ -1,32 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Types - -@class RLMPerson; - -#pragma mark - Defines & Constants - -extern const struct RLMDogAttributes { - __unsafe_unretained NSString *age; - __unsafe_unretained NSString *name; -} RLMDogAttributes; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMDog : RLMObject - -#pragma mark - Properties - -@property int age; -@property NSString *name; -@property (readonly) RLMPerson *owner; - -@end diff --git a/spec/fixtures/objc/inverse/RLMDog.m b/spec/fixtures/objc/inverse/RLMDog.m deleted file mode 100644 index 75d9e93..0000000 --- a/spec/fixtures/objc/inverse/RLMDog.m +++ /dev/null @@ -1,41 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMDog.h" - -#pragma mark - Defines & Constants - -const struct RLMDogAttributes RLMDogAttributes = { - .age = @"age", - .name = @"name" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMDog - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"age", @"name"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"age" : @(0), @"name" : @""}; -} - -- (RLMPerson *)owner -{ - return [[self linkingObjectsOfClass:@"RLMPerson" forProperty:@"dogs"] objectAtIndex:0]; -} - -@end diff --git a/spec/fixtures/objc/inverse/RLMPerson.h b/spec/fixtures/objc/inverse/RLMPerson.h deleted file mode 100644 index fc62a29..0000000 --- a/spec/fixtures/objc/inverse/RLMPerson.h +++ /dev/null @@ -1,30 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMProtocols.h" - -#pragma mark - Types - -@class RLMDog; - -#pragma mark - Defines & Constants - -extern const struct RLMPersonRelationships { - __unsafe_unretained NSString *dogs; -} RLMPersonRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMPerson : RLMObject - -#pragma mark - Properties - -@property RLMArray *dogs; - -@end diff --git a/spec/fixtures/objc/inverse/RLMPerson.m b/spec/fixtures/objc/inverse/RLMPerson.m deleted file mode 100644 index 0897ff8..0000000 --- a/spec/fixtures/objc/inverse/RLMPerson.m +++ /dev/null @@ -1,21 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMPerson.h" - -#pragma mark - Defines & Constants - -const struct RLMPersonRelationships RLMPersonRelationships = { - .dogs = @"dogs" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMPerson - -@end diff --git a/spec/fixtures/objc/inverse/RLMProtocols.h b/spec/fixtures/objc/inverse/RLMProtocols.h deleted file mode 100644 index 91fec23..0000000 --- a/spec/fixtures/objc/inverse/RLMProtocols.h +++ /dev/null @@ -1,8 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Protocols - -// This protocol enables typed collections. i.e.: RLMArray -RLM_ARRAY_TYPE(RLMDog) diff --git a/spec/fixtures/objc/json/JSON/RLMProduct+JSON.h b/spec/fixtures/objc/json/JSON/RLMProduct+JSON.h deleted file mode 100644 index a25b636..0000000 --- a/spec/fixtures/objc/json/JSON/RLMProduct+JSON.h +++ /dev/null @@ -1,16 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMProduct.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMProduct (JSON) - -@end diff --git a/spec/fixtures/objc/json/JSON/RLMProduct+JSON.m b/spec/fixtures/objc/json/JSON/RLMProduct+JSON.m deleted file mode 100644 index d5463be..0000000 --- a/spec/fixtures/objc/json/JSON/RLMProduct+JSON.m +++ /dev/null @@ -1,29 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMProduct+JSON.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMProduct (JSON) - -+ (NSDictionary *)JSONInboundMappingDictionary -{ - return @{ - @"shop" : @"shop" - }; -} - -+ (NSDictionary *)JSONOutboundMappingDictionary -{ - return @{ - @"shop" : @"shop" - }; -} - -@end diff --git a/spec/fixtures/objc/json/JSON/RLMShop+JSON.h b/spec/fixtures/objc/json/JSON/RLMShop+JSON.h deleted file mode 100644 index d410b9f..0000000 --- a/spec/fixtures/objc/json/JSON/RLMShop+JSON.h +++ /dev/null @@ -1,16 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMShop.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop (JSON) - -@end diff --git a/spec/fixtures/objc/json/JSON/RLMShop+JSON.m b/spec/fixtures/objc/json/JSON/RLMShop+JSON.m deleted file mode 100644 index 32f2b57..0000000 --- a/spec/fixtures/objc/json/JSON/RLMShop+JSON.m +++ /dev/null @@ -1,31 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop+JSON.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop (JSON) - -+ (NSDictionary *)JSONInboundMappingDictionary -{ - return @{ - @"json_name" : @"name", - @"products_key_json" : @"products" - }; -} - -+ (NSDictionary *)JSONOutboundMappingDictionary -{ - return @{ - @"name" : @"json_name", - @"products" : @"products_key_json" - }; -} - -@end diff --git a/spec/fixtures/objc/json/RLMProduct.h b/spec/fixtures/objc/json/RLMProduct.h deleted file mode 100644 index 441d9a3..0000000 --- a/spec/fixtures/objc/json/RLMProduct.h +++ /dev/null @@ -1,29 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Types - -@class RLMShop; - -#pragma mark - Defines & Constants - -extern const struct RLMProductRelationships { - __unsafe_unretained NSString *shop; -} RLMProductRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMProduct : RLMObject - -#pragma mark - Properties - -@property RLMShop *shop; - -@end diff --git a/spec/fixtures/objc/json/RLMProduct.m b/spec/fixtures/objc/json/RLMProduct.m deleted file mode 100644 index 0cb4666..0000000 --- a/spec/fixtures/objc/json/RLMProduct.m +++ /dev/null @@ -1,21 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMProduct.h" - -#pragma mark - Defines & Constants - -const struct RLMProductRelationships RLMProductRelationships = { - .shop = @"shop" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMProduct - -@end diff --git a/spec/fixtures/objc/json/RLMProtocols.h b/spec/fixtures/objc/json/RLMProtocols.h deleted file mode 100644 index 0836b24..0000000 --- a/spec/fixtures/objc/json/RLMProtocols.h +++ /dev/null @@ -1,8 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Protocols - -// This protocol enables typed collections. i.e.: RLMArray -RLM_ARRAY_TYPE(RLMProduct) diff --git a/spec/fixtures/objc/json/RLMShop.h b/spec/fixtures/objc/json/RLMShop.h deleted file mode 100644 index cf2bb70..0000000 --- a/spec/fixtures/objc/json/RLMShop.h +++ /dev/null @@ -1,35 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMProtocols.h" - -#pragma mark - Types - -@class RLMProduct; - -#pragma mark - Defines & Constants - -extern const struct RLMShopAttributes { - __unsafe_unretained NSString *name; -} RLMShopAttributes; - -extern const struct RLMShopRelationships { - __unsafe_unretained NSString *products; -} RLMShopRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop : RLMObject - -#pragma mark - Properties - -@property NSString *name; -@property RLMArray *products; - -@end diff --git a/spec/fixtures/objc/json/RLMShop.m b/spec/fixtures/objc/json/RLMShop.m deleted file mode 100644 index c7563c3..0000000 --- a/spec/fixtures/objc/json/RLMShop.m +++ /dev/null @@ -1,39 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop.h" - -#pragma mark - Defines & Constants - -const struct RLMShopAttributes RLMShopAttributes = { - .name = @"name" -}; - -const struct RLMShopRelationships RLMShopRelationships = { - .products = @"products" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"name"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"name" : @""}; -} - -@end diff --git a/spec/fixtures/objc/json_framework/JSON/RLMProduct+JSON.h b/spec/fixtures/objc/json_framework/JSON/RLMProduct+JSON.h deleted file mode 100644 index a3f45ec..0000000 --- a/spec/fixtures/objc/json_framework/JSON/RLMProduct+JSON.h +++ /dev/null @@ -1,16 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMObject+JSON.h" -#import "RLMProduct.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMProduct (JSON) - -@end diff --git a/spec/fixtures/objc/json_framework/JSON/RLMProduct+JSON.m b/spec/fixtures/objc/json_framework/JSON/RLMProduct+JSON.m deleted file mode 100644 index d5463be..0000000 --- a/spec/fixtures/objc/json_framework/JSON/RLMProduct+JSON.m +++ /dev/null @@ -1,29 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMProduct+JSON.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMProduct (JSON) - -+ (NSDictionary *)JSONInboundMappingDictionary -{ - return @{ - @"shop" : @"shop" - }; -} - -+ (NSDictionary *)JSONOutboundMappingDictionary -{ - return @{ - @"shop" : @"shop" - }; -} - -@end diff --git a/spec/fixtures/objc/json_framework/JSON/RLMShop+JSON.h b/spec/fixtures/objc/json_framework/JSON/RLMShop+JSON.h deleted file mode 100644 index 6e4f3d9..0000000 --- a/spec/fixtures/objc/json_framework/JSON/RLMShop+JSON.h +++ /dev/null @@ -1,16 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMObject+JSON.h" -#import "RLMShop.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop (JSON) - -@end diff --git a/spec/fixtures/objc/json_framework/JSON/RLMShop+JSON.m b/spec/fixtures/objc/json_framework/JSON/RLMShop+JSON.m deleted file mode 100644 index 32f2b57..0000000 --- a/spec/fixtures/objc/json_framework/JSON/RLMShop+JSON.m +++ /dev/null @@ -1,31 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop+JSON.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop (JSON) - -+ (NSDictionary *)JSONInboundMappingDictionary -{ - return @{ - @"json_name" : @"name", - @"products_key_json" : @"products" - }; -} - -+ (NSDictionary *)JSONOutboundMappingDictionary -{ - return @{ - @"name" : @"json_name", - @"products" : @"products_key_json" - }; -} - -@end diff --git a/spec/fixtures/objc/json_framework/RLMProduct.h b/spec/fixtures/objc/json_framework/RLMProduct.h deleted file mode 100644 index 441d9a3..0000000 --- a/spec/fixtures/objc/json_framework/RLMProduct.h +++ /dev/null @@ -1,29 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Types - -@class RLMShop; - -#pragma mark - Defines & Constants - -extern const struct RLMProductRelationships { - __unsafe_unretained NSString *shop; -} RLMProductRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMProduct : RLMObject - -#pragma mark - Properties - -@property RLMShop *shop; - -@end diff --git a/spec/fixtures/objc/json_framework/RLMProduct.m b/spec/fixtures/objc/json_framework/RLMProduct.m deleted file mode 100644 index 0cb4666..0000000 --- a/spec/fixtures/objc/json_framework/RLMProduct.m +++ /dev/null @@ -1,21 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMProduct.h" - -#pragma mark - Defines & Constants - -const struct RLMProductRelationships RLMProductRelationships = { - .shop = @"shop" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMProduct - -@end diff --git a/spec/fixtures/objc/json_framework/RLMProtocols.h b/spec/fixtures/objc/json_framework/RLMProtocols.h deleted file mode 100644 index 0836b24..0000000 --- a/spec/fixtures/objc/json_framework/RLMProtocols.h +++ /dev/null @@ -1,8 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Protocols - -// This protocol enables typed collections. i.e.: RLMArray -RLM_ARRAY_TYPE(RLMProduct) diff --git a/spec/fixtures/objc/json_framework/RLMShop.h b/spec/fixtures/objc/json_framework/RLMShop.h deleted file mode 100644 index cf2bb70..0000000 --- a/spec/fixtures/objc/json_framework/RLMShop.h +++ /dev/null @@ -1,35 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMProtocols.h" - -#pragma mark - Types - -@class RLMProduct; - -#pragma mark - Defines & Constants - -extern const struct RLMShopAttributes { - __unsafe_unretained NSString *name; -} RLMShopAttributes; - -extern const struct RLMShopRelationships { - __unsafe_unretained NSString *products; -} RLMShopRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop : RLMObject - -#pragma mark - Properties - -@property NSString *name; -@property RLMArray *products; - -@end diff --git a/spec/fixtures/objc/json_framework/RLMShop.m b/spec/fixtures/objc/json_framework/RLMShop.m deleted file mode 100644 index c7563c3..0000000 --- a/spec/fixtures/objc/json_framework/RLMShop.m +++ /dev/null @@ -1,39 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop.h" - -#pragma mark - Defines & Constants - -const struct RLMShopAttributes RLMShopAttributes = { - .name = @"name" -}; - -const struct RLMShopRelationships RLMShopRelationships = { - .products = @"products" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"name"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"name" : @""}; -} - -@end diff --git a/spec/fixtures/objc/no_value/JSON/RLMAnimal+JSON.h b/spec/fixtures/objc/no_value/JSON/RLMAnimal+JSON.h deleted file mode 100644 index b99454d..0000000 --- a/spec/fixtures/objc/no_value/JSON/RLMAnimal+JSON.h +++ /dev/null @@ -1,16 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMAnimal.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMAnimal (JSON) - -@end diff --git a/spec/fixtures/objc/no_value/JSON/RLMAnimal+JSON.m b/spec/fixtures/objc/no_value/JSON/RLMAnimal+JSON.m deleted file mode 100644 index 04de0a5..0000000 --- a/spec/fixtures/objc/no_value/JSON/RLMAnimal+JSON.m +++ /dev/null @@ -1,31 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMAnimal+JSON.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMAnimal (JSON) - -+ (NSDictionary *)JSONInboundMappingDictionary -{ - return @{ - @"attribute" : @"attribute", - @"relationshipNoValue" : @"relationshipNoValue" - }; -} - -+ (NSDictionary *)JSONOutboundMappingDictionary -{ - return @{ - @"attribute" : @"attribute", - @"relationshipNoValue" : @"relationshipNoValue" - }; -} - -@end diff --git a/spec/fixtures/objc/no_value/RLMAnimal.h b/spec/fixtures/objc/no_value/RLMAnimal.h deleted file mode 100644 index adbf2b6..0000000 --- a/spec/fixtures/objc/no_value/RLMAnimal.h +++ /dev/null @@ -1,31 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMProtocols.h" - -#pragma mark - Defines & Constants - -extern const struct RLMAnimalAttributes { - __unsafe_unretained NSString *attribute; -} RLMAnimalAttributes; - -extern const struct RLMAnimalRelationships { - __unsafe_unretained NSString *relationshipNoValue; -} RLMAnimalRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMAnimal : RLMObject - -#pragma mark - Properties - -@property NSString *attribute; -@property NSArray *relationshipNoValue; - -@end diff --git a/spec/fixtures/objc/no_value/RLMAnimal.m b/spec/fixtures/objc/no_value/RLMAnimal.m deleted file mode 100644 index a990074..0000000 --- a/spec/fixtures/objc/no_value/RLMAnimal.m +++ /dev/null @@ -1,27 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMAnimal.h" - -#pragma mark - Defines & Constants - -const struct RLMAnimalAttributes RLMAnimalAttributes = { - .attribute = @"attribute" -}; - -const struct RLMAnimalRelationships RLMAnimalRelationships = { - .relationshipNoValue = @"relationshipNoValue" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMAnimal - -#pragma mark - Superclass Overrides - -@end diff --git a/spec/fixtures/objc/optional/RLMFidelityCard.h b/spec/fixtures/objc/optional/RLMFidelityCard.h deleted file mode 100644 index 630841a..0000000 --- a/spec/fixtures/objc/optional/RLMFidelityCard.h +++ /dev/null @@ -1,36 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Types - -@class RLMUser; - -#pragma mark - Defines & Constants - -extern const struct RLMFidelityCardAttributes { - __unsafe_unretained NSString *identifier; - __unsafe_unretained NSString *points; -} RLMFidelityCardAttributes; - -extern const struct RLMFidelityCardRelationships { - __unsafe_unretained NSString *user; -} RLMFidelityCardRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMFidelityCard : RLMObject - -#pragma mark - Properties - -@property int identifier; -@property long points; -@property RLMUser *user; - -@end diff --git a/spec/fixtures/objc/optional/RLMFidelityCard.m b/spec/fixtures/objc/optional/RLMFidelityCard.m deleted file mode 100644 index d4db45d..0000000 --- a/spec/fixtures/objc/optional/RLMFidelityCard.m +++ /dev/null @@ -1,40 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMFidelityCard.h" - -#pragma mark - Defines & Constants - -const struct RLMFidelityCardAttributes RLMFidelityCardAttributes = { - .identifier = @"identifier", - .points = @"points" -}; - -const struct RLMFidelityCardRelationships RLMFidelityCardRelationships = { - .user = @"user" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMFidelityCard - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"identifier"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"identifier" : @(0)}; -} - -@end diff --git a/spec/fixtures/objc/optional/RLMProduct.h b/spec/fixtures/objc/optional/RLMProduct.h deleted file mode 100644 index 08d812a..0000000 --- a/spec/fixtures/objc/optional/RLMProduct.h +++ /dev/null @@ -1,29 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Defines & Constants - -extern const struct RLMProductAttributes { - __unsafe_unretained NSString *brand; - __unsafe_unretained NSString *name; - __unsafe_unretained NSString *price; -} RLMProductAttributes; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMProduct : RLMObject - -#pragma mark - Properties - -@property NSString *brand; -@property NSString *name; -@property long price; - -@end diff --git a/spec/fixtures/objc/optional/RLMProduct.m b/spec/fixtures/objc/optional/RLMProduct.m deleted file mode 100644 index 59873bf..0000000 --- a/spec/fixtures/objc/optional/RLMProduct.m +++ /dev/null @@ -1,37 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMProduct.h" - -#pragma mark - Defines & Constants - -const struct RLMProductAttributes RLMProductAttributes = { - .brand = @"brand", - .name = @"name", - .price = @"price" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMProduct - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"name"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"name" : @""}; -} - -@end diff --git a/spec/fixtures/objc/optional/RLMProtocols.h b/spec/fixtures/objc/optional/RLMProtocols.h deleted file mode 100644 index 0836b24..0000000 --- a/spec/fixtures/objc/optional/RLMProtocols.h +++ /dev/null @@ -1,8 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Protocols - -// This protocol enables typed collections. i.e.: RLMArray -RLM_ARRAY_TYPE(RLMProduct) diff --git a/spec/fixtures/objc/optional/RLMShop.h b/spec/fixtures/objc/optional/RLMShop.h deleted file mode 100644 index cf2bb70..0000000 --- a/spec/fixtures/objc/optional/RLMShop.h +++ /dev/null @@ -1,35 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMProtocols.h" - -#pragma mark - Types - -@class RLMProduct; - -#pragma mark - Defines & Constants - -extern const struct RLMShopAttributes { - __unsafe_unretained NSString *name; -} RLMShopAttributes; - -extern const struct RLMShopRelationships { - __unsafe_unretained NSString *products; -} RLMShopRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop : RLMObject - -#pragma mark - Properties - -@property NSString *name; -@property RLMArray *products; - -@end diff --git a/spec/fixtures/objc/optional/RLMShop.m b/spec/fixtures/objc/optional/RLMShop.m deleted file mode 100644 index c7563c3..0000000 --- a/spec/fixtures/objc/optional/RLMShop.m +++ /dev/null @@ -1,39 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop.h" - -#pragma mark - Defines & Constants - -const struct RLMShopAttributes RLMShopAttributes = { - .name = @"name" -}; - -const struct RLMShopRelationships RLMShopRelationships = { - .products = @"products" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"name"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"name" : @""}; -} - -@end diff --git a/spec/fixtures/objc/optional/RLMUser.h b/spec/fixtures/objc/optional/RLMUser.h deleted file mode 100644 index 982d379..0000000 --- a/spec/fixtures/objc/optional/RLMUser.h +++ /dev/null @@ -1,36 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Types - -@class RLMFidelityCard; - -#pragma mark - Defines & Constants - -extern const struct RLMUserAttributes { - __unsafe_unretained NSString *birthday; - __unsafe_unretained NSString *name; -} RLMUserAttributes; - -extern const struct RLMUserRelationships { - __unsafe_unretained NSString *fidelityCard; -} RLMUserRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMUser : RLMObject - -#pragma mark - Properties - -@property NSDate *birthday; -@property NSString *name; -@property RLMFidelityCard *fidelityCard; - -@end diff --git a/spec/fixtures/objc/optional/RLMUser.m b/spec/fixtures/objc/optional/RLMUser.m deleted file mode 100644 index ce35795..0000000 --- a/spec/fixtures/objc/optional/RLMUser.m +++ /dev/null @@ -1,40 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMUser.h" - -#pragma mark - Defines & Constants - -const struct RLMUserAttributes RLMUserAttributes = { - .birthday = @"birthday", - .name = @"name" -}; - -const struct RLMUserRelationships RLMUserRelationships = { - .fidelityCard = @"fidelityCard" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMUser - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"birthday", @"name"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"birthday" : [NSDate date], @"name" : @""}; -} - -@end diff --git a/spec/fixtures/objc/primary/RLMFidelityCard.h b/spec/fixtures/objc/primary/RLMFidelityCard.h deleted file mode 100644 index 630841a..0000000 --- a/spec/fixtures/objc/primary/RLMFidelityCard.h +++ /dev/null @@ -1,36 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Types - -@class RLMUser; - -#pragma mark - Defines & Constants - -extern const struct RLMFidelityCardAttributes { - __unsafe_unretained NSString *identifier; - __unsafe_unretained NSString *points; -} RLMFidelityCardAttributes; - -extern const struct RLMFidelityCardRelationships { - __unsafe_unretained NSString *user; -} RLMFidelityCardRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMFidelityCard : RLMObject - -#pragma mark - Properties - -@property int identifier; -@property long points; -@property RLMUser *user; - -@end diff --git a/spec/fixtures/objc/primary/RLMFidelityCard.m b/spec/fixtures/objc/primary/RLMFidelityCard.m deleted file mode 100644 index b83550a..0000000 --- a/spec/fixtures/objc/primary/RLMFidelityCard.m +++ /dev/null @@ -1,45 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMFidelityCard.h" - -#pragma mark - Defines & Constants - -const struct RLMFidelityCardAttributes RLMFidelityCardAttributes = { - .identifier = @"identifier", - .points = @"points" -}; - -const struct RLMFidelityCardRelationships RLMFidelityCardRelationships = { - .user = @"user" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMFidelityCard - -#pragma mark - Superclass Overrides - -+ (NSString *)primaryKey -{ - return @"identifier"; -} - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"points"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"points" : @(0)}; -} - -@end diff --git a/spec/fixtures/objc/primary/RLMProduct.h b/spec/fixtures/objc/primary/RLMProduct.h deleted file mode 100644 index 08d812a..0000000 --- a/spec/fixtures/objc/primary/RLMProduct.h +++ /dev/null @@ -1,29 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Defines & Constants - -extern const struct RLMProductAttributes { - __unsafe_unretained NSString *brand; - __unsafe_unretained NSString *name; - __unsafe_unretained NSString *price; -} RLMProductAttributes; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMProduct : RLMObject - -#pragma mark - Properties - -@property NSString *brand; -@property NSString *name; -@property long price; - -@end diff --git a/spec/fixtures/objc/primary/RLMProduct.m b/spec/fixtures/objc/primary/RLMProduct.m deleted file mode 100644 index 8577d09..0000000 --- a/spec/fixtures/objc/primary/RLMProduct.m +++ /dev/null @@ -1,42 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMProduct.h" - -#pragma mark - Defines & Constants - -const struct RLMProductAttributes RLMProductAttributes = { - .brand = @"brand", - .name = @"name", - .price = @"price" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMProduct - -#pragma mark - Superclass Overrides - -+ (NSString *)primaryKey -{ - return @"name"; -} - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"brand", @"price"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"brand" : @"", @"price" : @(0)}; -} - -@end diff --git a/spec/fixtures/objc/primary/RLMProtocols.h b/spec/fixtures/objc/primary/RLMProtocols.h deleted file mode 100644 index 0836b24..0000000 --- a/spec/fixtures/objc/primary/RLMProtocols.h +++ /dev/null @@ -1,8 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Protocols - -// This protocol enables typed collections. i.e.: RLMArray -RLM_ARRAY_TYPE(RLMProduct) diff --git a/spec/fixtures/objc/primary/RLMShop.h b/spec/fixtures/objc/primary/RLMShop.h deleted file mode 100644 index cf2bb70..0000000 --- a/spec/fixtures/objc/primary/RLMShop.h +++ /dev/null @@ -1,35 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMProtocols.h" - -#pragma mark - Types - -@class RLMProduct; - -#pragma mark - Defines & Constants - -extern const struct RLMShopAttributes { - __unsafe_unretained NSString *name; -} RLMShopAttributes; - -extern const struct RLMShopRelationships { - __unsafe_unretained NSString *products; -} RLMShopRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop : RLMObject - -#pragma mark - Properties - -@property NSString *name; -@property RLMArray *products; - -@end diff --git a/spec/fixtures/objc/primary/RLMShop.m b/spec/fixtures/objc/primary/RLMShop.m deleted file mode 100644 index 113b9e0..0000000 --- a/spec/fixtures/objc/primary/RLMShop.m +++ /dev/null @@ -1,32 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop.h" - -#pragma mark - Defines & Constants - -const struct RLMShopAttributes RLMShopAttributes = { - .name = @"name" -}; - -const struct RLMShopRelationships RLMShopRelationships = { - .products = @"products" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop - -#pragma mark - Superclass Overrides - -+ (NSString *)primaryKey -{ - return @"name"; -} - -@end diff --git a/spec/fixtures/objc/primary/RLMUser.h b/spec/fixtures/objc/primary/RLMUser.h deleted file mode 100644 index 982d379..0000000 --- a/spec/fixtures/objc/primary/RLMUser.h +++ /dev/null @@ -1,36 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Types - -@class RLMFidelityCard; - -#pragma mark - Defines & Constants - -extern const struct RLMUserAttributes { - __unsafe_unretained NSString *birthday; - __unsafe_unretained NSString *name; -} RLMUserAttributes; - -extern const struct RLMUserRelationships { - __unsafe_unretained NSString *fidelityCard; -} RLMUserRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMUser : RLMObject - -#pragma mark - Properties - -@property NSDate *birthday; -@property NSString *name; -@property RLMFidelityCard *fidelityCard; - -@end diff --git a/spec/fixtures/objc/primary/RLMUser.m b/spec/fixtures/objc/primary/RLMUser.m deleted file mode 100644 index 558810d..0000000 --- a/spec/fixtures/objc/primary/RLMUser.m +++ /dev/null @@ -1,45 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMUser.h" - -#pragma mark - Defines & Constants - -const struct RLMUserAttributes RLMUserAttributes = { - .birthday = @"birthday", - .name = @"name" -}; - -const struct RLMUserRelationships RLMUserRelationships = { - .fidelityCard = @"fidelityCard" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMUser - -#pragma mark - Superclass Overrides - -+ (NSString *)primaryKey -{ - return @"name"; -} - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"birthday"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"birthday" : [NSDate date]}; -} - -@end diff --git a/spec/fixtures/objc/realm/RLMFidelityCard.h b/spec/fixtures/objc/realm/RLMFidelityCard.h deleted file mode 100644 index 630841a..0000000 --- a/spec/fixtures/objc/realm/RLMFidelityCard.h +++ /dev/null @@ -1,36 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Types - -@class RLMUser; - -#pragma mark - Defines & Constants - -extern const struct RLMFidelityCardAttributes { - __unsafe_unretained NSString *identifier; - __unsafe_unretained NSString *points; -} RLMFidelityCardAttributes; - -extern const struct RLMFidelityCardRelationships { - __unsafe_unretained NSString *user; -} RLMFidelityCardRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMFidelityCard : RLMObject - -#pragma mark - Properties - -@property int identifier; -@property long points; -@property RLMUser *user; - -@end diff --git a/spec/fixtures/objc/realm/RLMFidelityCard.m b/spec/fixtures/objc/realm/RLMFidelityCard.m deleted file mode 100644 index 404bf64..0000000 --- a/spec/fixtures/objc/realm/RLMFidelityCard.m +++ /dev/null @@ -1,40 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMFidelityCard.h" - -#pragma mark - Defines & Constants - -const struct RLMFidelityCardAttributes RLMFidelityCardAttributes = { - .identifier = @"identifier", - .points = @"points" -}; - -const struct RLMFidelityCardRelationships RLMFidelityCardRelationships = { - .user = @"user" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMFidelityCard - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"identifier", @"points"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"identifier" : @(0), @"points" : @(0)}; -} - -@end diff --git a/spec/fixtures/objc/realm/RLMProduct.h b/spec/fixtures/objc/realm/RLMProduct.h deleted file mode 100644 index 08d812a..0000000 --- a/spec/fixtures/objc/realm/RLMProduct.h +++ /dev/null @@ -1,29 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Defines & Constants - -extern const struct RLMProductAttributes { - __unsafe_unretained NSString *brand; - __unsafe_unretained NSString *name; - __unsafe_unretained NSString *price; -} RLMProductAttributes; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMProduct : RLMObject - -#pragma mark - Properties - -@property NSString *brand; -@property NSString *name; -@property long price; - -@end diff --git a/spec/fixtures/objc/realm/RLMProduct.m b/spec/fixtures/objc/realm/RLMProduct.m deleted file mode 100644 index adeeecd..0000000 --- a/spec/fixtures/objc/realm/RLMProduct.m +++ /dev/null @@ -1,37 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMProduct.h" - -#pragma mark - Defines & Constants - -const struct RLMProductAttributes RLMProductAttributes = { - .brand = @"brand", - .name = @"name", - .price = @"price" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMProduct - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"brand", @"name", @"price"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"brand" : @"", @"name" : @"", @"price" : @(0)}; -} - -@end diff --git a/spec/fixtures/objc/realm/RLMProtocols.h b/spec/fixtures/objc/realm/RLMProtocols.h deleted file mode 100644 index 0836b24..0000000 --- a/spec/fixtures/objc/realm/RLMProtocols.h +++ /dev/null @@ -1,8 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Protocols - -// This protocol enables typed collections. i.e.: RLMArray -RLM_ARRAY_TYPE(RLMProduct) diff --git a/spec/fixtures/objc/realm/RLMShop.h b/spec/fixtures/objc/realm/RLMShop.h deleted file mode 100644 index cf2bb70..0000000 --- a/spec/fixtures/objc/realm/RLMShop.h +++ /dev/null @@ -1,35 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMProtocols.h" - -#pragma mark - Types - -@class RLMProduct; - -#pragma mark - Defines & Constants - -extern const struct RLMShopAttributes { - __unsafe_unretained NSString *name; -} RLMShopAttributes; - -extern const struct RLMShopRelationships { - __unsafe_unretained NSString *products; -} RLMShopRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop : RLMObject - -#pragma mark - Properties - -@property NSString *name; -@property RLMArray *products; - -@end diff --git a/spec/fixtures/objc/realm/RLMShop.m b/spec/fixtures/objc/realm/RLMShop.m deleted file mode 100644 index c7563c3..0000000 --- a/spec/fixtures/objc/realm/RLMShop.m +++ /dev/null @@ -1,39 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop.h" - -#pragma mark - Defines & Constants - -const struct RLMShopAttributes RLMShopAttributes = { - .name = @"name" -}; - -const struct RLMShopRelationships RLMShopRelationships = { - .products = @"products" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"name"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"name" : @""}; -} - -@end diff --git a/spec/fixtures/objc/realm/RLMUser.h b/spec/fixtures/objc/realm/RLMUser.h deleted file mode 100644 index 982d379..0000000 --- a/spec/fixtures/objc/realm/RLMUser.h +++ /dev/null @@ -1,36 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Types - -@class RLMFidelityCard; - -#pragma mark - Defines & Constants - -extern const struct RLMUserAttributes { - __unsafe_unretained NSString *birthday; - __unsafe_unretained NSString *name; -} RLMUserAttributes; - -extern const struct RLMUserRelationships { - __unsafe_unretained NSString *fidelityCard; -} RLMUserRelationships; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMUser : RLMObject - -#pragma mark - Properties - -@property NSDate *birthday; -@property NSString *name; -@property RLMFidelityCard *fidelityCard; - -@end diff --git a/spec/fixtures/objc/realm/RLMUser.m b/spec/fixtures/objc/realm/RLMUser.m deleted file mode 100644 index ce35795..0000000 --- a/spec/fixtures/objc/realm/RLMUser.m +++ /dev/null @@ -1,40 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMUser.h" - -#pragma mark - Defines & Constants - -const struct RLMUserAttributes RLMUserAttributes = { - .birthday = @"birthday", - .name = @"name" -}; - -const struct RLMUserRelationships RLMUserRelationships = { - .fidelityCard = @"fidelityCard" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMUser - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"birthday", @"name"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"birthday" : [NSDate date], @"name" : @""}; -} - -@end diff --git a/spec/fixtures/objc/transformers/JSON/RLMShop+JSON.h b/spec/fixtures/objc/transformers/JSON/RLMShop+JSON.h deleted file mode 100644 index d410b9f..0000000 --- a/spec/fixtures/objc/transformers/JSON/RLMShop+JSON.h +++ /dev/null @@ -1,16 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import -#import "RLMShop.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop (JSON) - -@end diff --git a/spec/fixtures/objc/transformers/JSON/RLMShop+JSON.m b/spec/fixtures/objc/transformers/JSON/RLMShop+JSON.m deleted file mode 100644 index 56aa44d..0000000 --- a/spec/fixtures/objc/transformers/JSON/RLMShop+JSON.m +++ /dev/null @@ -1,76 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop+JSON.h" -#import "CustomDateTransformer.h" -#import "MPDecimalTransformer.h" -#import "MPIntegerTransformer.h" - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop (JSON) - -+ (NSDictionary *)JSONInboundMappingDictionary -{ - return @{ - @"attrDate" : @"attrDate", - @"attrDateCustom" : @"attrDateCustom", - @"attrDecimal" : @"attrDecimal", - @"attrDouble" : @"attrDouble", - @"attrFloat" : @"attrFloat", - @"attrInteger16" : @"attrInteger16", - @"attrInteger32" : @"attrInteger32", - @"attrInteger64" : @"attrInteger64" - }; -} - -+ (NSDictionary *)JSONOutboundMappingDictionary -{ - return @{ - @"attrDate" : @"attrDate", - @"attrDateCustom" : @"attrDateCustom", - @"attrDecimal" : @"attrDecimal", - @"attrDouble" : @"attrDouble", - @"attrFloat" : @"attrFloat", - @"attrInteger16" : @"attrInteger16", - @"attrInteger32" : @"attrInteger32", - @"attrInteger64" : @"attrInteger64" - }; -} - -+ (NSValueTransformer *)attrDateJSONTransformer -{ - return [[ISO8601DateTransform alloc] init]; -} - -+ (NSValueTransformer *)attrDateCustomJSONTransformer -{ - return [[CustomDateTransformer alloc] init]; -} - -+ (NSValueTransformer *)attrDecimalJSONTransformer -{ - return [[MPDecimalTransformer alloc] init]; -} - -+ (NSValueTransformer *)attrFloatJSONTransformer -{ - return [[MPDecimalTransformer alloc] init]; -} - -+ (NSValueTransformer *)attrInteger16JSONTransformer -{ - return [[MPIntegerTransformer alloc] init]; -} - -+ (NSValueTransformer *)attrInteger64JSONTransformer -{ - return [[MPIntegerTransformer alloc] init]; -} - -@end diff --git a/spec/fixtures/objc/transformers/RLMShop.h b/spec/fixtures/objc/transformers/RLMShop.h deleted file mode 100644 index c50126c..0000000 --- a/spec/fixtures/objc/transformers/RLMShop.h +++ /dev/null @@ -1,39 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import - -#pragma mark - Defines & Constants - -extern const struct RLMShopAttributes { - __unsafe_unretained NSString *attrDate; - __unsafe_unretained NSString *attrDateCustom; - __unsafe_unretained NSString *attrDecimal; - __unsafe_unretained NSString *attrDouble; - __unsafe_unretained NSString *attrFloat; - __unsafe_unretained NSString *attrInteger16; - __unsafe_unretained NSString *attrInteger32; - __unsafe_unretained NSString *attrInteger64; -} RLMShopAttributes; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Interface - -@interface RLMShop : RLMObject - -#pragma mark - Properties - -@property NSDate *attrDate; -@property NSDate *attrDateCustom; -@property double attrDecimal; -@property double attrDouble; -@property float attrFloat; -@property int attrInteger16; -@property long attrInteger32; -@property long long attrInteger64; - -@end diff --git a/spec/fixtures/objc/transformers/RLMShop.m b/spec/fixtures/objc/transformers/RLMShop.m deleted file mode 100644 index b84c0f4..0000000 --- a/spec/fixtures/objc/transformers/RLMShop.m +++ /dev/null @@ -1,42 +0,0 @@ -// DO NOT EDIT | Generated by gyro - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Imports - -#import "RLMShop.h" - -#pragma mark - Defines & Constants - -const struct RLMShopAttributes RLMShopAttributes = { - .attrDate = @"attrDate", - .attrDateCustom = @"attrDateCustom", - .attrDecimal = @"attrDecimal", - .attrDouble = @"attrDouble", - .attrFloat = @"attrFloat", - .attrInteger16 = @"attrInteger16", - .attrInteger32 = @"attrInteger32", - .attrInteger64 = @"attrInteger64" -}; - -//////////////////////////////////////////////////////////////////////////////// - -#pragma mark - Implementation - -@implementation RLMShop - -#pragma mark - Superclass Overrides - -// Specify required properties -+ (NSArray *)requiredProperties -{ - return @[@"attrDecimal", @"attrDouble", @"attrFloat", @"attrInteger16", @"attrInteger32", @"attrInteger64"]; -} - -// Specify default values for required properties -+ (NSDictionary *)defaultPropertyValues -{ - return @{@"attrDecimal" : @(0.0), @"attrDouble" : @(0.0), @"attrFloat" : @(0.0), @"attrInteger16" : @(0), @"attrInteger32" : @(0), @"attrInteger64" : @(0)}; -} - -@end diff --git a/spec/fixtures/swift/enum/OptValue.swift b/spec/fixtures/swift/enum/OptValue.swift index 21e655e..6082895 100644 --- a/spec/fixtures/swift/enum/OptValue.swift +++ b/spec/fixtures/swift/enum/OptValue.swift @@ -1,7 +1,7 @@ /* DO NOT EDIT | Generated by gyro */ enum OptValue: String { - case OptValueOne = "opt_value_one" - case OptValueTwo = "opt_value_two" - case OptValueThree = "opt_value_three" + case optValueOne = "OptValueOne" + case optValueTwo = "OptValueTwo" + case optValueThree = "OptValueThree" } diff --git a/spec/fixtures/swift/enum/Shop.swift b/spec/fixtures/swift/enum/Shop.swift index 5e1d0e4..e37297d 100644 --- a/spec/fixtures/swift/enum/Shop.swift +++ b/spec/fixtures/swift/enum/Shop.swift @@ -4,32 +4,34 @@ import RealmSwift final class Shop: Object { - enum Attributes: String { - case Name = "name" - case OptionalValue = "optionalValue" - case Type = "type" - } + enum Attributes: String { + case name = "name" + case optionalValue = "optionalValue" + case type = "type" + } + + dynamic var name: String = "" - dynamic var name: String = "" - dynamic var optionalValue: String? = nil - var optionalValueEnum: OptValue? { - get { - guard let optionalValue = optionalValue, - let enumValue = OptValue(rawValue: optionalValue) - else { return nil } - return enumValue - } - set { optionalValue = newValue?.rawValue ?? nil } + dynamic var optionalValue: String? + var optionalValueEnum: OptValue? { + get { + guard let optionalValue = optionalValue, + let enumValue = OptValue(rawValue: optionalValue) + else { return nil } + return enumValue } + set { optionalValue = newValue?.rawValue ?? nil } + } + - dynamic var type: String = "" - var typeEnum: Type? { - get { - guard let enumValue = Type(rawValue: type) else { return nil } - return enumValue - } - set { type = newValue?.rawValue ?? "" } + dynamic var type: String = "" + var typeEnum: Type? { + get { + guard let enumValue = Type(rawValue: type) else { return nil } + return enumValue } + set { type = newValue?.rawValue ?? "" } + } } diff --git a/spec/fixtures/swift/enum/Type.swift b/spec/fixtures/swift/enum/Type.swift index 344e0e3..ab10eab 100644 --- a/spec/fixtures/swift/enum/Type.swift +++ b/spec/fixtures/swift/enum/Type.swift @@ -1,7 +1,7 @@ /* DO NOT EDIT | Generated by gyro */ enum Type: String { - case TypeOne = "type_one" - case TypeTwo = "type_two" - case TypeThree = "type_three" + case typeOne = "TypeOne" + case typeTwo = "TypeTwo" + case typeThree = "TypeThree" } diff --git a/spec/fixtures/swift/ignored/Owner.swift b/spec/fixtures/swift/ignored/Owner.swift index 84649d9..3c74cd9 100644 --- a/spec/fixtures/swift/ignored/Owner.swift +++ b/spec/fixtures/swift/ignored/Owner.swift @@ -4,20 +4,20 @@ import RealmSwift final class Owner: Object { - enum Attributes: String { - case Name = "name" - } + enum Attributes: String { + case name = "name" + } - enum Relationships: String { - case Shop = "shop" - } + enum Relationships: String { + case shop = "shop" + } - dynamic var name: String? = nil - dynamic var shop: Shop? + dynamic var name: String? + dynamic var shop: Shop? - // Specify properties to ignore (Realm won't persist these) - override static func ignoredProperties() -> [String] { - return ["shop"] - } + // Specify properties to ignore (Realm won't persist these) + override static func ignoredProperties() -> [String] { + return ["shop"] + } } diff --git a/spec/fixtures/swift/ignored/Product.swift b/spec/fixtures/swift/ignored/Product.swift index 9b465a0..609b3bb 100644 --- a/spec/fixtures/swift/ignored/Product.swift +++ b/spec/fixtures/swift/ignored/Product.swift @@ -4,10 +4,10 @@ import RealmSwift final class Product: Object { - enum Relationships: String { - case Shop = "shop" - } + enum Relationships: String { + case shop = "shop" + } - dynamic var shop: Shop? + dynamic var shop: Shop? } diff --git a/spec/fixtures/swift/ignored/Shop.swift b/spec/fixtures/swift/ignored/Shop.swift index d526978..ea58552 100644 --- a/spec/fixtures/swift/ignored/Shop.swift +++ b/spec/fixtures/swift/ignored/Shop.swift @@ -4,23 +4,26 @@ import RealmSwift final class Shop: Object { - enum Attributes: String { - case Name = "name" - } + enum Attributes: String { + case ignored = "ignored" + case ignored2 = "ignored2" + case name = "name" + } - enum Relationships: String { - case Owner = "owner" - case Products = "products" - } + enum Relationships: String { + case owner = "owner" + case products = "products" + } - dynamic var ignored: String = "" - dynamic var name: String = "" - dynamic var owner: Owner? - let products = List() + dynamic var ignored: String = "" + dynamic var ignored2: String = "" + dynamic var name: String = "" + dynamic var owner: Owner? + let products = List() - // Specify properties to ignore (Realm won't persist these) - override static func ignoredProperties() -> [String] { - return ["ignored"] - } + // Specify properties to ignore (Realm won't persist these) + override static func ignoredProperties() -> [String] { + return ["ignored","ignored2"] + } } diff --git a/spec/fixtures/swift/inverse/Dog.swift b/spec/fixtures/swift/inverse/Dog.swift index f07b016..b1785fc 100644 --- a/spec/fixtures/swift/inverse/Dog.swift +++ b/spec/fixtures/swift/inverse/Dog.swift @@ -4,15 +4,15 @@ import RealmSwift final class Dog: Object { - enum Attributes: String { - case Age = "age" - case Name = "name" - } + enum Attributes: String { + case age = "age" + case name = "name" + } - dynamic var age: Int16 = 0 - dynamic var name: String = "" - - let owners = LinkingObjects(fromType: Person.self, property: "dogs") - var owner: Person? { return owners.first } + dynamic var age: Int16 = 0 + dynamic var name: String = "" + + let owners = LinkingObjects(fromType: Person.self, property: "dogs") + var owner: Person? { return owners.first } } diff --git a/spec/fixtures/swift/inverse/Person.swift b/spec/fixtures/swift/inverse/Person.swift index 2d6ede5..f29b53c 100644 --- a/spec/fixtures/swift/inverse/Person.swift +++ b/spec/fixtures/swift/inverse/Person.swift @@ -4,10 +4,10 @@ import RealmSwift final class Person: Object { - enum Relationships: String { - case Dogs = "dogs" - } + enum Relationships: String { + case dogs = "dogs" + } - let dogs = List() + let dogs = List() } diff --git a/spec/fixtures/swift/optional/FidelityCard.swift b/spec/fixtures/swift/optional/FidelityCard.swift index 30c39f8..433be6b 100644 --- a/spec/fixtures/swift/optional/FidelityCard.swift +++ b/spec/fixtures/swift/optional/FidelityCard.swift @@ -4,17 +4,17 @@ import RealmSwift final class FidelityCard: Object { - enum Attributes: String { - case Identifier = "identifier" - case Points = "points" - } + enum Attributes: String { + case identifier = "identifier" + case points = "points" + } - enum Relationships: String { - case User = "user" - } + enum Relationships: String { + case user = "user" + } - dynamic var identifier: Int16 = 0 - let points = RealmOptional() - dynamic var user: User? + dynamic var identifier: Int16 = 0 + let points = RealmOptional() + dynamic var user: User? } diff --git a/spec/fixtures/swift/optional/Product.swift b/spec/fixtures/swift/optional/Product.swift index 9db668e..8fd72f8 100644 --- a/spec/fixtures/swift/optional/Product.swift +++ b/spec/fixtures/swift/optional/Product.swift @@ -4,14 +4,14 @@ import RealmSwift final class Product: Object { - enum Attributes: String { - case Brand = "brand" - case Name = "name" - case Price = "price" - } + enum Attributes: String { + case brand = "brand" + case name = "name" + case price = "price" + } - dynamic var brand: String? = nil - dynamic var name: String = "" - let price = RealmOptional() + dynamic var brand: String? + dynamic var name: String = "" + let price = RealmOptional() } diff --git a/spec/fixtures/swift/optional/Shop.swift b/spec/fixtures/swift/optional/Shop.swift index b89344d..cc52f23 100644 --- a/spec/fixtures/swift/optional/Shop.swift +++ b/spec/fixtures/swift/optional/Shop.swift @@ -4,15 +4,15 @@ import RealmSwift final class Shop: Object { - enum Attributes: String { - case Name = "name" - } + enum Attributes: String { + case name = "name" + } - enum Relationships: String { - case Products = "products" - } + enum Relationships: String { + case products = "products" + } - dynamic var name: String = "" - let products = List() + dynamic var name: String = "" + let products = List() } diff --git a/spec/fixtures/swift/optional/User.swift b/spec/fixtures/swift/optional/User.swift index 903cb33..db517ac 100644 --- a/spec/fixtures/swift/optional/User.swift +++ b/spec/fixtures/swift/optional/User.swift @@ -4,17 +4,17 @@ import RealmSwift final class User: Object { - enum Attributes: String { - case Birthday = "birthday" - case Name = "name" - } + enum Attributes: String { + case birthday = "birthday" + case name = "name" + } - enum Relationships: String { - case FidelityCard = "fidelityCard" - } + enum Relationships: String { + case fidelityCard = "fidelityCard" + } - dynamic var birthday: NSDate = NSDate() - dynamic var name: String = "" - dynamic var fidelityCard: FidelityCard? + dynamic var birthday: Date = Date() + dynamic var name: String = "" + dynamic var fidelityCard: FidelityCard? } diff --git a/spec/fixtures/swift/primary/FidelityCard.swift b/spec/fixtures/swift/primary/FidelityCard.swift index 16f555b..7ce51ec 100644 --- a/spec/fixtures/swift/primary/FidelityCard.swift +++ b/spec/fixtures/swift/primary/FidelityCard.swift @@ -4,21 +4,21 @@ import RealmSwift final class FidelityCard: Object { - enum Attributes: String { - case Identifier = "identifier" - case Points = "points" - } + enum Attributes: String { + case identifier = "identifier" + case points = "points" + } - enum Relationships: String { - case User = "user" - } + enum Relationships: String { + case user = "user" + } - dynamic var identifier: Int16 = 0 - dynamic var points: Int32 = 0 - dynamic var user: User? + dynamic var identifier: Int16 = 0 + dynamic var points: Int32 = 0 + dynamic var user: User? - override static func primaryKey() -> String? { - return "identifier" - } + override static func primaryKey() -> String? { + return "identifier" + } } diff --git a/spec/fixtures/swift/primary/Product.swift b/spec/fixtures/swift/primary/Product.swift index 08aa730..641eb6f 100644 --- a/spec/fixtures/swift/primary/Product.swift +++ b/spec/fixtures/swift/primary/Product.swift @@ -4,18 +4,18 @@ import RealmSwift final class Product: Object { - enum Attributes: String { - case Brand = "brand" - case Name = "name" - case Price = "price" - } + enum Attributes: String { + case brand = "brand" + case name = "name" + case price = "price" + } - dynamic var brand: String = "" - dynamic var name: String = "" - dynamic var price: Int32 = 0 + dynamic var brand: String = "" + dynamic var name: String = "" + dynamic var price: Int32 = 0 - override static func primaryKey() -> String? { - return "name" - } + override static func primaryKey() -> String? { + return "name" + } } diff --git a/spec/fixtures/swift/primary/Shop.swift b/spec/fixtures/swift/primary/Shop.swift index c7170e9..ff6e417 100644 --- a/spec/fixtures/swift/primary/Shop.swift +++ b/spec/fixtures/swift/primary/Shop.swift @@ -4,19 +4,19 @@ import RealmSwift final class Shop: Object { - enum Attributes: String { - case Name = "name" - } + enum Attributes: String { + case name = "name" + } - enum Relationships: String { - case Products = "products" - } + enum Relationships: String { + case products = "products" + } - dynamic var name: String = "" - let products = List() + dynamic var name: String = "" + let products = List() - override static func primaryKey() -> String? { - return "name" - } + override static func primaryKey() -> String? { + return "name" + } } diff --git a/spec/fixtures/swift/primary/User.swift b/spec/fixtures/swift/primary/User.swift index 7ec6816..7dff97c 100644 --- a/spec/fixtures/swift/primary/User.swift +++ b/spec/fixtures/swift/primary/User.swift @@ -4,21 +4,21 @@ import RealmSwift final class User: Object { - enum Attributes: String { - case Birthday = "birthday" - case Name = "name" - } + enum Attributes: String { + case birthday = "birthday" + case name = "name" + } - enum Relationships: String { - case FidelityCard = "fidelityCard" - } + enum Relationships: String { + case fidelityCard = "fidelityCard" + } - dynamic var birthday: NSDate = NSDate() - dynamic var name: String = "" - dynamic var fidelityCard: FidelityCard? + dynamic var birthday: Date = Date() + dynamic var name: String = "" + dynamic var fidelityCard: FidelityCard? - override static func primaryKey() -> String? { - return "name" - } + override static func primaryKey() -> String? { + return "name" + } } diff --git a/spec/fixtures/swift/realm/FidelityCard.swift b/spec/fixtures/swift/realm/FidelityCard.swift index 7f2795c..e101b3d 100644 --- a/spec/fixtures/swift/realm/FidelityCard.swift +++ b/spec/fixtures/swift/realm/FidelityCard.swift @@ -4,17 +4,17 @@ import RealmSwift final class FidelityCard: Object { - enum Attributes: String { - case Identifier = "identifier" - case Points = "points" - } + enum Attributes: String { + case identifier = "identifier" + case points = "points" + } - enum Relationships: String { - case User = "user" - } + enum Relationships: String { + case user = "user" + } - dynamic var identifier: Int16 = 0 - dynamic var points: Int32 = 0 - dynamic var user: User? + dynamic var identifier: Int16 = 0 + dynamic var points: Int32 = 0 + dynamic var user: User? } diff --git a/spec/fixtures/swift/realm/Product.swift b/spec/fixtures/swift/realm/Product.swift index 59d9196..ad507a6 100644 --- a/spec/fixtures/swift/realm/Product.swift +++ b/spec/fixtures/swift/realm/Product.swift @@ -4,14 +4,14 @@ import RealmSwift final class Product: Object { - enum Attributes: String { - case Brand = "brand" - case Name = "name" - case Price = "price" - } + enum Attributes: String { + case brand = "brand" + case name = "name" + case price = "price" + } - dynamic var brand: String = "" - dynamic var name: String = "" - dynamic var price: Int32 = 0 + dynamic var brand: String = "" + dynamic var name: String = "" + dynamic var price: Int32 = 0 } diff --git a/spec/fixtures/swift/realm/Shop.swift b/spec/fixtures/swift/realm/Shop.swift index b89344d..cc52f23 100644 --- a/spec/fixtures/swift/realm/Shop.swift +++ b/spec/fixtures/swift/realm/Shop.swift @@ -4,15 +4,15 @@ import RealmSwift final class Shop: Object { - enum Attributes: String { - case Name = "name" - } + enum Attributes: String { + case name = "name" + } - enum Relationships: String { - case Products = "products" - } + enum Relationships: String { + case products = "products" + } - dynamic var name: String = "" - let products = List() + dynamic var name: String = "" + let products = List() } diff --git a/spec/fixtures/swift/realm/User.swift b/spec/fixtures/swift/realm/User.swift index 903cb33..db517ac 100644 --- a/spec/fixtures/swift/realm/User.swift +++ b/spec/fixtures/swift/realm/User.swift @@ -4,17 +4,17 @@ import RealmSwift final class User: Object { - enum Attributes: String { - case Birthday = "birthday" - case Name = "name" - } + enum Attributes: String { + case birthday = "birthday" + case name = "name" + } - enum Relationships: String { - case FidelityCard = "fidelityCard" - } + enum Relationships: String { + case fidelityCard = "fidelityCard" + } - dynamic var birthday: NSDate = NSDate() - dynamic var name: String = "" - dynamic var fidelityCard: FidelityCard? + dynamic var birthday: Date = Date() + dynamic var name: String = "" + dynamic var fidelityCard: FidelityCard? } diff --git a/spec/fixtures/swift/transformers/ObjectMapper/ShopMapper.swift b/spec/fixtures/swift/transformers/ObjectMapper/ShopMapper.swift index bd1c590..40f6cad 100644 --- a/spec/fixtures/swift/transformers/ObjectMapper/ShopMapper.swift +++ b/spec/fixtures/swift/transformers/ObjectMapper/ShopMapper.swift @@ -5,23 +5,20 @@ import ObjectMapper extension Shop: Mappable { // MARK: Initializers - - convenience init?(_ map: Map) { + convenience init?(map: Map) { self.init() } // MARK: Mappable - func mapping(map: Map) { - // MARK: Attributes self.attrDate <- (map["attrDate"], ISO8601DateTransform()) self.attrDateCustom <- (map["attrDateCustom"], CustomDateTransformer()) - self.attrDecimal <- map["attrDecimal"] + self.attrDecimal <- (map["attrDecimal"], MPDecimalTransformer()) self.attrDouble <- map["attrDouble"] - self.attrFloat <- map["attrFloat"] - self.attrInteger16 <- map["attrInteger16"] + self.attrFloat <- (map["attrFloat"], MPDecimalTransformer()) + self.attrInteger16 <- (map["attrInteger16"], MPIntegerTransformer()) self.attrInteger32 <- map["attrInteger32"] - self.attrInteger64 <- map["attrInteger64"] + self.attrInteger64 <- (map["attrInteger64"], MPIntegerTransformer()) } } diff --git a/spec/fixtures/swift/transformers/decodable/Shop+Decodable.swift b/spec/fixtures/swift/transformers/decodable/Shop+Decodable.swift new file mode 100644 index 0000000..0784c59 --- /dev/null +++ b/spec/fixtures/swift/transformers/decodable/Shop+Decodable.swift @@ -0,0 +1,19 @@ +/* DO NOT EDIT | Generated by gyro */ + +import protocol Decodable.Decodable +import Decodable + +extension Shop: Decodable { + + static func decode(_ json: Any) throws -> Shop { + let shop = Shop() + shop.attrDate = try Date.decode(json => "attrDate") + shop.attrDateCustom = try Date.decode(json => "attrDateCustom") + shop.attrDouble = try json => "attrDouble" + shop.attrInteger16 = try Int.decode(json => "attrInteger16") + shop.attrInteger32 = try json => "attrInteger32" + shop.attrInteger64 = try Int.decode(json => "attrInteger64") + return shop + } + +} \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/bool.xcdatamodel/contents b/spec/fixtures/xcdatamodel/bool.xcdatamodel/contents index 4fc2571..7337822 100644 --- a/spec/fixtures/xcdatamodel/bool.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/bool.xcdatamodel/contents @@ -1,11 +1,11 @@ - - - - + + + + - + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/entity.xcdatamodel/contents b/spec/fixtures/xcdatamodel/entity.xcdatamodel/contents index 77a8aba..a4da592 100644 --- a/spec/fixtures/xcdatamodel/entity.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/entity.xcdatamodel/contents @@ -1,10 +1,10 @@ - - + + - + - + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/enum.xcdatamodel/contents b/spec/fixtures/xcdatamodel/enum.xcdatamodel/contents index cb67770..a9d1d6b 100644 --- a/spec/fixtures/xcdatamodel/enum.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/enum.xcdatamodel/contents @@ -1,6 +1,6 @@ - - + + @@ -10,12 +10,12 @@ - - + + - + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/enum_json.xcdatamodel/contents b/spec/fixtures/xcdatamodel/enum_json.xcdatamodel/contents index caa8b6b..7fc083f 100644 --- a/spec/fixtures/xcdatamodel/enum_json.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/enum_json.xcdatamodel/contents @@ -1,25 +1,25 @@ - - + + - + - - + + - + - - + + - + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/enum_multi.xcdatamodel/contents b/spec/fixtures/xcdatamodel/enum_multi.xcdatamodel/contents index 5514da7..80b5437 100644 --- a/spec/fixtures/xcdatamodel/enum_multi.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/enum_multi.xcdatamodel/contents @@ -1,47 +1,47 @@ - - - - - + + + + + - + - - + + - - + + - + - + - + - - + + - + - - + + - + - - + + - + - - - - + + + + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/error_enum_json.xcdatamodel/contents b/spec/fixtures/xcdatamodel/error_enum_json.xcdatamodel/contents index f29b103..2aea112 100644 --- a/spec/fixtures/xcdatamodel/error_enum_json.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/error_enum_json.xcdatamodel/contents @@ -1,7 +1,7 @@ - - - + + + @@ -9,6 +9,6 @@ - + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/error_enum_type.xcdatamodel/contents b/spec/fixtures/xcdatamodel/error_enum_type.xcdatamodel/contents index 53cc693..4e2a1eb 100644 --- a/spec/fixtures/xcdatamodel/error_enum_type.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/error_enum_type.xcdatamodel/contents @@ -1,15 +1,15 @@ - - + + - + - + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/error_relationship.xcdatamodel/contents b/spec/fixtures/xcdatamodel/error_relationship.xcdatamodel/contents index ac3852c..af9af9a 100644 --- a/spec/fixtures/xcdatamodel/error_relationship.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/error_relationship.xcdatamodel/contents @@ -1,12 +1,13 @@ - - - - - + + + + + + + - - + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/error_undefined_type.xcdatamodel/contents b/spec/fixtures/xcdatamodel/error_undefined_type.xcdatamodel/contents index c8f9109..1332cb9 100644 --- a/spec/fixtures/xcdatamodel/error_undefined_type.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/error_undefined_type.xcdatamodel/contents @@ -1,11 +1,11 @@ - - + + - - + + - + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/global.xcdatamodel/contents b/spec/fixtures/xcdatamodel/global.xcdatamodel/contents index 592949f..7a01423 100644 --- a/spec/fixtures/xcdatamodel/global.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/global.xcdatamodel/contents @@ -1,36 +1,35 @@ - - - + + + - - - - + + + + - + - + - + - + - - + + - - + + - - - - - - - + + + + + + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/ignored.xcdatamodel/contents b/spec/fixtures/xcdatamodel/ignored.xcdatamodel/contents index f27a96e..8b12ff2 100644 --- a/spec/fixtures/xcdatamodel/ignored.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/ignored.xcdatamodel/contents @@ -1,20 +1,25 @@ - - + + - + - - + + - + - + + + + + + @@ -23,12 +28,12 @@ - - + + - - - + + + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/inverse.xcdatamodel/contents b/spec/fixtures/xcdatamodel/inverse.xcdatamodel/contents index 974fc9a..9114862 100644 --- a/spec/fixtures/xcdatamodel/inverse.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/inverse.xcdatamodel/contents @@ -1,15 +1,15 @@ - - - + + + - + - - + + - - + + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/json_key_path.xcdatamodel/contents b/spec/fixtures/xcdatamodel/json_key_path.xcdatamodel/contents index b024081..28d2ea7 100644 --- a/spec/fixtures/xcdatamodel/json_key_path.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/json_key_path.xcdatamodel/contents @@ -1,22 +1,22 @@ - - - + + + - + - + - - + + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/optional.xcdatamodel/contents b/spec/fixtures/xcdatamodel/optional.xcdatamodel/contents index 32fb99e..1a3ef8e 100644 --- a/spec/fixtures/xcdatamodel/optional.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/optional.xcdatamodel/contents @@ -1,32 +1,32 @@ - - + + - + - + - + - + - + - + - - - - + + + + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/primary.xcdatamodel/contents b/spec/fixtures/xcdatamodel/primary.xcdatamodel/contents index 5c9ca2b..950c5e6 100644 --- a/spec/fixtures/xcdatamodel/primary.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/primary.xcdatamodel/contents @@ -1,40 +1,40 @@ - - - - - + + + + + - + - + - + - + - - + + - + - - - - + + + + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/read_only.xcdatamodel/contents b/spec/fixtures/xcdatamodel/read_only.xcdatamodel/contents index dd6a703..ab38ea2 100644 --- a/spec/fixtures/xcdatamodel/read_only.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/read_only.xcdatamodel/contents @@ -1,13 +1,16 @@ - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/realm.xcdatamodel/contents b/spec/fixtures/xcdatamodel/realm.xcdatamodel/contents index 95ddfb2..26044a4 100644 --- a/spec/fixtures/xcdatamodel/realm.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/realm.xcdatamodel/contents @@ -1,28 +1,28 @@ - - - - - + + + + + - + - + - + - + - - + + - + - - - - + + + + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/relationship.xcdatamodel/contents b/spec/fixtures/xcdatamodel/relationship.xcdatamodel/contents index 56ecc60..11bd8c8 100644 --- a/spec/fixtures/xcdatamodel/relationship.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/relationship.xcdatamodel/contents @@ -1,15 +1,14 @@ - - + + - + - - - + + - - + + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/relationship_type.xcdatamodel/contents b/spec/fixtures/xcdatamodel/relationship_type.xcdatamodel/contents index 2cc6738..6906964 100644 --- a/spec/fixtures/xcdatamodel/relationship_type.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/relationship_type.xcdatamodel/contents @@ -1,6 +1,6 @@ - - + + @@ -9,6 +9,6 @@ - + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/transformers-decodable.xcdatamodel/contents b/spec/fixtures/xcdatamodel/transformers-decodable.xcdatamodel/contents new file mode 100644 index 0000000..7164239 --- /dev/null +++ b/spec/fixtures/xcdatamodel/transformers-decodable.xcdatamodel/contents @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spec/fixtures/xcdatamodel/transformers.xcdatamodel/contents b/spec/fixtures/xcdatamodel/transformers.xcdatamodel/contents index 092ece6..fd9c58e 100644 --- a/spec/fixtures/xcdatamodel/transformers.xcdatamodel/contents +++ b/spec/fixtures/xcdatamodel/transformers.xcdatamodel/contents @@ -1,6 +1,6 @@ - - + + @@ -31,6 +31,6 @@ - + \ No newline at end of file diff --git a/spec/gyro/liquid_generator_java_spec.rb b/spec/gyro/liquid_generator_java_spec.rb new file mode 100644 index 0000000..6dacf70 --- /dev/null +++ b/spec/gyro/liquid_generator_java_spec.rb @@ -0,0 +1,102 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +PACKAGE_NAME = 'com.gyro.tests'.freeze +ANDROID_TEMPLATE_DIR = 'lib/templates/android'.freeze + +module Gyro + describe 'Liquid' do + describe 'Java' do + before do + Gyro::Log.quiet = true + end + + %w[realm primary ignored inverse enum enum_multi enum_json].each do |datamodel| + it datamodel do + xcdatamodel_dir = fixture('xcdatamodel', "#{datamodel}.xcdatamodel") + xcdatamodel = Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) + + Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| + template_dir = Pathname.new(ANDROID_TEMPLATE_DIR) + gen = Generator::Liquid.new(template_dir, tmp_dir, 'package' => PACKAGE_NAME) + gen.generate(xcdatamodel) + fixtures_files_dir = fixture('java', datamodel) + compare_dirs(tmp_dir, fixtures_files_dir) + end + end + end + + it 'json' do + xcdatamodel_dir = fixture('xcdatamodel', 'json_key_path.xcdatamodel') + xcdatamodel = Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) + Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| + template_dir = Pathname.new(ANDROID_TEMPLATE_DIR) + gen = Generator::Liquid.new(template_dir, tmp_dir, 'package' => PACKAGE_NAME) + gen.generate(xcdatamodel) + fixtures_files_dir = fixture('java', 'json') + compare_dirs(tmp_dir, fixtures_files_dir) + end + end + + it 'with wrapper types' do + xcdatamodel_dir = fixture('xcdatamodel', 'optional.xcdatamodel') + xcdatamodel = Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) + Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| + template_dir = Pathname.new(ANDROID_TEMPLATE_DIR) + gen = Generator::Liquid.new(template_dir, tmp_dir, 'package' => PACKAGE_NAME, 'use_wrappers' => 'true') + gen.generate(xcdatamodel) + fixtures_files_dir = fixture('java', 'wrappers') + compare_dirs(tmp_dir, fixtures_files_dir) + end + end + + it 'with annotations' do + xcdatamodel_dir = fixture('xcdatamodel', 'optional.xcdatamodel') + xcdatamodel = Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) + Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| + template_dir = Pathname.new(ANDROID_TEMPLATE_DIR) + gen = Generator::Liquid.new(template_dir, tmp_dir, 'package' => PACKAGE_NAME, 'support_annotations' => 'true') + gen.generate(xcdatamodel) + fixtures_files_dir = fixture('java', 'annotations') + compare_dirs(tmp_dir, fixtures_files_dir) + end + end + + it 'with wrapper types and annotations' do + xcdatamodel_dir = fixture('xcdatamodel', 'optional.xcdatamodel') + xcdatamodel = Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) + Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| + template_dir = Pathname.new(ANDROID_TEMPLATE_DIR) + options = { 'package' => PACKAGE_NAME, 'use_wrappers' => 'true', 'support_annotations' => 'true' } + gen = Generator::Liquid.new(template_dir, tmp_dir, options) + gen.generate(xcdatamodel) + fixtures_files_dir = fixture('java', 'wrappers_annotations') + compare_dirs(tmp_dir, fixtures_files_dir) + end + end + + it 'relationship without value' do + xcdatamodel_dir = fixture('xcdatamodel', 'relationship_type.xcdatamodel') + xcdatamodel = Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) + Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| + template_dir = Pathname.new(ANDROID_TEMPLATE_DIR) + gen = Generator::Liquid.new(template_dir, tmp_dir, 'package' => PACKAGE_NAME) + gen.generate(xcdatamodel) + fixtures_files_dir = fixture('java', 'no_value') + compare_dirs(tmp_dir, fixtures_files_dir) + end + end + end + end +end diff --git a/spec/gyro/liquid_generator_swift_spec.rb b/spec/gyro/liquid_generator_swift_spec.rb new file mode 100644 index 0000000..4eca2b7 --- /dev/null +++ b/spec/gyro/liquid_generator_swift_spec.rb @@ -0,0 +1,65 @@ +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SWIFT3_TEMPLATE_DIR = 'lib/templates/swift3'.freeze +OBJMAPPER_TEMPLATE_DIR = 'lib/templates/object-mapper'.freeze +DECODABLE_TEMPLATE_DIR = 'lib/templates/decodable'.freeze + +module Gyro + describe 'Liquid' do + describe 'Swift' do + before do + Gyro::Log.quiet = true + end + + %w[realm primary ignored inverse enum optional].each do |datamodel| + it datamodel do + xcdatamodel_dir = fixture('xcdatamodel', "#{datamodel}.xcdatamodel") + xcdatamodel = Gyro::Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) + Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| + template_dir = Pathname.new(SWIFT3_TEMPLATE_DIR) + gen = Generator::Liquid.new(template_dir, tmp_dir, {}) + gen.generate(xcdatamodel) + fixtures_files_dir = fixture('swift', datamodel) + compare_dirs(tmp_dir, fixtures_files_dir) + end + end + end + + it 'transformer object mapper' do + xcdatamodel_dir = fixture('xcdatamodel', 'transformers.xcdatamodel') + xcdatamodel = Gyro::Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) + Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| + template_dir = Pathname.new(OBJMAPPER_TEMPLATE_DIR) + gen = Generator::Liquid.new(template_dir, tmp_dir, {}) + gen.generate(xcdatamodel) + fixtures_files_dir = fixture('swift', 'transformers', 'ObjectMapper') + compare_dirs(tmp_dir, fixtures_files_dir) + end + end + + it 'transformer decodable' do + xcdatamodel_dir = fixture('xcdatamodel', 'transformers-decodable.xcdatamodel') + xcdatamodel = Gyro::Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) + Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| + template_dir = Pathname.new(DECODABLE_TEMPLATE_DIR) + gen = Generator::Liquid.new(template_dir, tmp_dir, {}) + gen.generate(xcdatamodel) + fixtures_files_dir = fixture('swift', 'transformers', 'decodable') + compare_dirs(tmp_dir, fixtures_files_dir) + end + end + end + end +end diff --git a/spec/gyro/realm_generator_java_spec.rb b/spec/gyro/realm_generator_java_spec.rb deleted file mode 100644 index 7f26d79..0000000 --- a/spec/gyro/realm_generator_java_spec.rb +++ /dev/null @@ -1,148 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -require 'tmpdir' - -PACKAGE_NAME = 'com.gyro.tests' - -module Gyro - describe Realm do - - it 'Realm Java' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/realm.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/java/realm', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Java primary' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/primary.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/java/primary', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Java ignored' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/ignored.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/java/ignored', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Java enum simple' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/enum.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/java/enum', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Java enum multi' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/enum_multi.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/java/enum_multi', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Java json' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/json_key_path.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/java/json', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Java json with enum' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/enum_json.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/java/enum_json', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Java with wrapper types' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/optional.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel) - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel, true) - fixtures_files_dir = File.expand_path('../fixtures/java/wrappers', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Java with annotations' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/optional.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel) - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel, false, true) - fixtures_files_dir = File.expand_path('../fixtures/java/annotations', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Java with wrapper types and annotations' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/optional.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel) - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel, true, true) - fixtures_files_dir = File.expand_path('../fixtures/java/wrappers_annotations', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Java inverse' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/inverse.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/java/inverse', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Java relationship without value' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/relationship_type.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::Java::Generator.new(tmp_dir, PACKAGE_NAME, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/java/no_value', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - end -end diff --git a/spec/gyro/realm_generator_objc_spec.rb b/spec/gyro/realm_generator_objc_spec.rb deleted file mode 100644 index 9b47d01..0000000 --- a/spec/gyro/realm_generator_objc_spec.rb +++ /dev/null @@ -1,161 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -require 'tmpdir' - -module Gyro - describe Realm do - - it 'Realm ObjC' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/realm.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::ObjC::Generator.new(tmp_dir, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/objc/realm', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm ObjC primary' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/primary.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::ObjC::Generator.new(tmp_dir, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/objc/primary', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm ObjC optional' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/optional.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::ObjC::Generator.new(tmp_dir, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/objc/optional', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm ObjC ignored' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/ignored.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::ObjC::Generator.new(tmp_dir, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/objc/ignored', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm ObjC enum simple' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/enum.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::ObjC::Generator.new(tmp_dir, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/objc/enum', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm ObjC enum multi' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/enum_multi.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::ObjC::Generator.new(tmp_dir, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/objc/enum_multi', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm ObjC json' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/json_key_path.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::ObjC::Generator.new(tmp_dir, xcdatamodel, true) - fixtures_files_dir = File.expand_path('../fixtures/objc/json', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm ObjC json with Framework' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/json_key_path.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::ObjC::Generator.new(tmp_dir, xcdatamodel, true, true) - fixtures_files_dir = File.expand_path('../fixtures/objc/json_framework', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm ObjC json with enum' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/enum_json.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::ObjC::Generator.new(tmp_dir, xcdatamodel, true) - fixtures_files_dir = File.expand_path('../fixtures/objc/enum_json', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm ObjC check raising enum json error' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/error_enum_json.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - expect { Realm::ObjC::Generator.new(tmp_dir, xcdatamodel, true) }.to raise_error "\e[1;31m! The attribute \"type\" from \"RLMShop\" is enum without JSONValues - please fix it\e[0m" - end - end - - it 'Realm ObjC json with bool' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/bool.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::ObjC::Generator.new(tmp_dir, xcdatamodel, true) - fixtures_files_dir = File.expand_path('../fixtures/objc/bool', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm ObjC inverse' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/inverse.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::ObjC::Generator.new(tmp_dir, xcdatamodel, false) - fixtures_files_dir = File.expand_path('../fixtures/objc/inverse', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm ObjC json with number' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/transformers.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::ObjC::Generator.new(tmp_dir, xcdatamodel, true) - fixtures_files_dir = File.expand_path('../fixtures/objc/transformers', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm ObjC relationship without value' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/relationship_type.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Realm::ObjC::Generator.new(tmp_dir, xcdatamodel, true) - fixtures_files_dir = File.expand_path('../fixtures/objc/no_value', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - end -end diff --git a/spec/gyro/realm_generator_swift_spec.rb b/spec/gyro/realm_generator_swift_spec.rb deleted file mode 100644 index 6c17ecc..0000000 --- a/spec/gyro/realm_generator_swift_spec.rb +++ /dev/null @@ -1,93 +0,0 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end - -require 'tmpdir' - -module Gyro - describe Realm do - - it 'Realm Swift' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/realm.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Gyro::Realm::Swift::Generator.new(tmp_dir, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/swift/realm', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Swift primary' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/primary.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Gyro::Realm::Swift::Generator.new(tmp_dir, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/swift/primary', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Swift ignored' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/ignored.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Gyro::Realm::Swift::Generator.new(tmp_dir, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/swift/ignored', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Swift inverse' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/inverse.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Gyro::Realm::Swift::Generator.new(tmp_dir, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/swift/inverse', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Swift enum' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/enum.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Gyro::Realm::Swift::Generator.new(tmp_dir, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/swift/enum', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Swift optional' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/optional.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Gyro::Realm::Swift::Generator.new(tmp_dir, xcdatamodel) - fixtures_files_dir = File.expand_path('../fixtures/swift/optional', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - it 'Realm Swift tranformers for ObjectMapper' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/transformers.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = Gyro::XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) - Dir.mktmpdir(TMP_DIR_NAME) do |tmp_dir| - Gyro::Realm::Swift::Generator.new(tmp_dir, xcdatamodel, true) - fixtures_files_dir = File.expand_path('../fixtures/swift/transformers', File.dirname(__FILE__)) - compare_dirs(tmp_dir, fixtures_files_dir) - end - end - - end -end diff --git a/spec/gyro/xcdatamodel_spec.rb b/spec/gyro/xcdatamodel_spec.rb index 27aee45..96b6a23 100644 --- a/spec/gyro/xcdatamodel_spec.rb +++ b/spec/gyro/xcdatamodel_spec.rb @@ -1,56 +1,54 @@ -=begin -Copyright 2016 - Niji - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. module Gyro - - describe XCDataModel do + describe Parser::XCDataModel do + before do + Gyro::Log.quiet = true + end it 'check raise an error for file' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/not_found.xcdatamodel', File.dirname(__FILE__)) - expect { XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) }.to raise_error "\e[1;31m! Unable to find contents of xcdatamodel dir\e[0m" + xcdatamodel_dir = fixture('xcdatamodel', 'not_found.xcdatamodel') + expect { Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) } + .to raise_error 'Unable to find contents of xcdatamodel' end it 'check raising relationship error' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/error_relationship.xcdatamodel', File.dirname(__FILE__)) - expect { XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) }.to raise_error "\e[1;31m! The relationship \"user\" from \"RLMFidelityCard\" is wrong - please fix it\e[0m" + xcdatamodel_dir = fixture('xcdatamodel', 'error_relationship.xcdatamodel') + expect { Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) } + .to raise_error 'The relationship "user" from "FidelityCard" is wrong - please fix it' end it 'check raising undefined type error' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/error_undefined_type.xcdatamodel', File.dirname(__FILE__)) - expect { XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) }.to raise_error "\e[1;31m! The attribute \"name\" from \"RLMProduct\" has no type - please fix it\e[0m" - end - - it 'check raising enum type error' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/error_enum_type.xcdatamodel', File.dirname(__FILE__)) - expect { XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) }.to raise_error "\e[1;31m! The attribute \"type\" from \"RLMShop\" is enum with incorrect type (not Integer) - please fix it\e[0m" + xcdatamodel_dir = fixture('xcdatamodel', 'error_undefined_type.xcdatamodel') + expect { Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) } + .to raise_error 'The attribute "name" from "Product" has no type - please fix it' end it 'check abstract entity' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/entity.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) + xcdatamodel_dir = fixture('xcdatamodel', 'entity.xcdatamodel') + xcdatamodel = Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) expect(xcdatamodel.entities.length).to eq 1 entity = xcdatamodel.entities.values.first - expect(entity.name).to eq 'DBAnimal' + expect(entity.name).to eq 'Animal' expect(entity.parent).to eq '' expect(entity.abstract?).to be true end it 'check attribute' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/entity.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) + xcdatamodel_dir = fixture('xcdatamodel', 'entity.xcdatamodel') + xcdatamodel = Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) expect(xcdatamodel.entities.length).to eq 1 entity = xcdatamodel.entities.values.first expect(entity.attributes.length).to eq 1 @@ -61,19 +59,19 @@ module Gyro end it 'check relationship' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/relationship.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) + xcdatamodel_dir = fixture('xcdatamodel', 'relationship.xcdatamodel') + xcdatamodel = Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) expect(xcdatamodel.entities.length).to eq 2 - entity_1, entity_2 = xcdatamodel.entities.values - relationship = entity_1.relationships.values.first - relationship_inverse = entity_2.relationships.values.first + entity1, entity2 = xcdatamodel.entities.values + relationship = entity1.relationships.values.first + relationship_inverse = entity2.relationships.values.first expect(relationship.inverse_name).to eq(relationship_inverse.name) expect(relationship_inverse.inverse_name).to eq(relationship.name) end it 'check relationship without destination' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/relationship_type.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) + xcdatamodel_dir = fixture('xcdatamodel', 'relationship_type.xcdatamodel') + xcdatamodel = Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) expect(xcdatamodel.entities.length).to eq 1 entity = xcdatamodel.entities.values.first expect(entity.relationships.length).to eq 1 @@ -84,10 +82,9 @@ module Gyro end it 'check global xcdatamodel' do - xcdatamodel_dir = File.expand_path('../fixtures/xcdatamodel/global.xcdatamodel', File.dirname(__FILE__)) - xcdatamodel = XCDataModel::Parser::XCDataModel.new(xcdatamodel_dir) + xcdatamodel_dir = fixture('xcdatamodel', 'global.xcdatamodel') + xcdatamodel = Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir) expect(xcdatamodel.entities.length).to eq 6 end - end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9b7ac0d..0ad436b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,57 +1,42 @@ -=begin -Copyright 2016 - Niji +# Copyright 2016 - Niji +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 +require 'gyro' +require 'tmpdir' -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -=end +TMP_DIR_NAME = 'Gyro'.freeze +FIXTURES_DIR = (Pathname.new(__FILE__).parent + 'fixtures').freeze -if $0 == __FILE__ - $:.unshift File.expand_path('../lib', File.dirname(__FILE__)) +def fixture(*paths) + FIXTURES_DIR.join(*paths) end -require 'gyro' +def compare_dirs(generated_files_dir, fixtures_dir) + generated_dir = Pathname.new(generated_files_dir) -TMP_DIR_NAME = 'Gyro' + fixtures_files = fixtures_dir.find.select { |file| File.file?(file) } + # expect(files_count(generated_dir)).to eq fixtures_files.count + check_files_count(generated_dir, fixtures_files.count) -def find_file(dir, file_name) - Dir.chdir(dir) do - files = Dir.glob("**/#{file_name}") - File.expand_path(files.first, dir) + fixtures_files.each do |fixture| + generated_file = generated_dir + fixture.relative_path_from(fixtures_dir) + expect(generated_file.read).to eq(fixture.read), "File: '#{fixture}' differ from expectation." end end -def compare_dirs(generated_files_dir, fixtures_files_dir) - generated_files = Dir[File.join(generated_files_dir, '**', '*')] - # puts generated_files - # generated_files.each { |generated_file| - # File.open(generated_file) { |file| - # puts file.read unless File.directory?(file) - # } - # } - nb_generated_files = generated_files.count { |file| File.file?(file) } - fixtures_files = Dir[File.join(fixtures_files_dir, '**', '*')] - nb_fixtures_files = fixtures_files.count { |file| File.file?(file) } - expect(nb_generated_files).to eq nb_fixtures_files - fixtures_files.each { |fixtures_file| - if File.file?(fixtures_file) - file = File.open(fixtures_file, 'rb') - fixture_file_content = file.read - file.close - file_name = File.basename(fixtures_file) - generated_file = find_file(generated_files_dir, file_name) - file = File.open(generated_file, 'rb') - generated_file_content = file.read - file.close - expect(generated_file_content).to eq fixture_file_content - end - } +def check_files_count(dir, expected_count) + count = dir.find.select { |f| File.file?(f) }.count + expect(count).to eq expected_count end +private :check_files_count