gyro 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/bin/gyro +5 -1
  3. data/lib/gyro/log.rb +12 -11
  4. data/lib/gyro/parser/xcdatamodel/attribute.rb +2 -2
  5. data/lib/gyro/parser/xcdatamodel/relationship.rb +5 -4
  6. data/lib/gyro/parser/xcdatamodel/xcdatamodel.rb +11 -5
  7. data/lib/gyro/template.rb +57 -33
  8. data/lib/gyro/version.rb +1 -1
  9. data/lib/templates/android-java/README.md +8 -6
  10. data/lib/templates/android-java/inc/_relationships_enum.liquid +3 -0
  11. data/lib/templates/android-kotlin/README.md +12 -10
  12. data/lib/templates/android-kotlin/enum.liquid +1 -1
  13. data/lib/templates/android-kotlin/inc/_relationships_enum.liquid +3 -0
  14. data/lib/templates/{decodable → anviking-decodable}/README.md +0 -0
  15. data/lib/templates/{decodable → anviking-decodable}/entity.liquid +0 -0
  16. data/lib/templates/{decodable → anviking-decodable}/entity_filename.liquid +0 -0
  17. data/lib/templates/{decodable → anviking-decodable}/enum.liquid +0 -0
  18. data/lib/templates/{decodable → anviking-decodable}/enum_filename.liquid +0 -0
  19. data/lib/templates/config.yml +25 -0
  20. data/lib/templates/swift3-variant/README.md +5 -5
  21. data/lib/templates/swift3-variant/entity.liquid +3 -0
  22. data/lib/templates/swift3-variant/inc/_attributes_enum.liquid +1 -1
  23. data/lib/templates/swift3-variant/inc/_relationships_enum.liquid +3 -0
  24. data/lib/templates/swift3/README.md +10 -2
  25. data/lib/templates/swift3/entity.liquid +1 -1
  26. data/lib/templates/swift3/enum.liquid +1 -1
  27. data/lib/templates/swift3/inc/_attributes_enum.liquid +1 -1
  28. data/lib/templates/swift3/inc/_attributes_properties.liquid +1 -1
  29. data/lib/templates/swift3/inc/_enum_attribute_property.liquid +3 -3
  30. data/lib/templates/swift3/inc/_ignored_properties.liquid +1 -1
  31. data/lib/templates/swift3/inc/_indexed_properties.liquid +1 -1
  32. data/lib/templates/swift3/inc/_inverse_properties.liquid +3 -3
  33. data/lib/templates/swift3/inc/_optional_attribute_property.liquid +2 -2
  34. data/lib/templates/swift3/inc/_primary_key.liquid +1 -1
  35. data/lib/templates/swift3/inc/_relationship_properties.liquid +2 -2
  36. data/lib/templates/swift3/inc/_relationships_enum.liquid +1 -1
  37. metadata +7 -8
  38. data/lib/templates/android.alias +0 -10
  39. data/lib/templates/swift4.alias +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e5f08df0670a25b7dc526fa689e6c92ae3e510f
4
- data.tar.gz: f46dabd9dc80b7eb665af3cf3b732c3d647784c0
3
+ metadata.gz: 0bf0426491e18b9a47860737ea3d6dc2747f9873
4
+ data.tar.gz: 076fc086a2c155072ef315cf2eacbe9618dd8c4c
5
5
  SHA512:
6
- metadata.gz: c73b447c3038e8c3a3b949984e6bb600519c2fe2dbbb44b9a989d4e31ce61bb384a594a68e1ebac0d2a149af557c7e482d9d70ac574d4ab25e37e891b6c2f2db
7
- data.tar.gz: 8f16dae895a213e8e637ded30569eff086e2ce7d33cf88ddebd02dc34cad3fd27d729c9fbfa1bcb5581baa477725460c0f1d172c0e7764bf8fce47d900e062ec
6
+ metadata.gz: ffac77775f2eb5aabe39c3b59a9e7c895fdcc936945652e48f2c8c7f3a8fc4f780b430a302dd9e47541e5ebef8bdad4e983a1af71df60e2f51fae3c8af97a047
7
+ data.tar.gz: 30b87e1da934dbbf2f297962013eac1d384d8424ca5cb65f61d988c4663d5f0775cdcf605a1a1486be43a47c9fe7904a860bda396efd71661650f218a97c08da
data/bin/gyro CHANGED
@@ -76,6 +76,7 @@ rescue OptionParser::ParseError => e
76
76
  exit 1
77
77
  end
78
78
 
79
+ # Model directory parsing
79
80
  if options[:model].nil?
80
81
  Gyro::Log.info('No model provided, trying to find one in the local directory…')
81
82
  options[:model] = Gyro::Parser::XCDataModel.find_in_dir(dir)
@@ -90,6 +91,8 @@ else
90
91
  Gyro::Log.success("Using #{basename} in #{dirname}")
91
92
  end
92
93
 
94
+ xcdatamodel_dir = Pathname.new(options[:model])
95
+
93
96
  # Liquid Templates
94
97
  if options[:template].nil?
95
98
  # Generate JSON if no -t is specified
@@ -114,12 +117,13 @@ end
114
117
  puts <<-INFO.gsub(/ \|/, '')
115
118
  |
116
119
  |#===================================
120
+ |# Model : #{xcdatamodel_dir}
117
121
  |# Template : #{template_dir}
118
122
  |# Output Dir : #{output_dir}
119
123
  |# Params : #{options[:params].inspect}
120
124
  |#===================================
121
125
  INFO
122
126
 
123
- xcdatamodel = Gyro::Parser::XCDataModel::XCDataModel.new(options[:model])
127
+ xcdatamodel = Gyro::Parser::XCDataModel::XCDataModel.new(xcdatamodel_dir)
124
128
  gen = Gyro::Generator::Liquid.new(template_dir, output_dir, options[:params])
125
129
  gen.generate(xcdatamodel)
@@ -16,30 +16,30 @@ module Gyro
16
16
  # Print nice and colored output for various error/success/title messages of Gyro
17
17
  #
18
18
  module Log
19
- @quiet = false
20
- def self.quiet=(value)
21
- @quiet = value
19
+ @in_test_context = false
20
+ def self.in_test_context=(value)
21
+ @in_test_context = value
22
22
  end
23
23
 
24
24
  def self.title(str) # bg yellow
25
- puts "\n#{str.colorize(:gray, :blue)}" unless @quiet
25
+ puts "\n#{str.colorize(:gray, :blue)}" unless @in_test_context
26
26
  end
27
27
 
28
28
  def self.error(str)
29
- puts "! #{str}".colorize(:red, :bold) unless @quiet
29
+ puts "! #{str}".colorize(:red, :bold) unless @in_test_context
30
30
  end
31
31
 
32
32
  def self.info(str)
33
- puts "> #{str}".colorize(:yellow, :bold) unless @quiet
33
+ puts "> #{str}".colorize(:yellow, :bold) unless @in_test_context
34
34
  end
35
35
 
36
36
  def self.success(str)
37
- puts "√ #{str}".colorize(:green, :bold) unless @quiet
37
+ puts "√ #{str}".colorize(:green, :bold) unless @in_test_context
38
38
  end
39
39
 
40
- def self.fail!(message, stacktrace: false)
40
+ def self.fail!(message)
41
41
  Gyro::Log.error message
42
- raise message if stacktrace
42
+ raise message if @in_test_context
43
43
  exit 1
44
44
  end
45
45
  end
@@ -51,8 +51,9 @@ class String
51
51
  ANSI_COLORS = %i[black red green yellow blue magenta cyan gray white].freeze
52
52
  ANSI_MODES = %i[normal bold faint italic underline blink].freeze
53
53
 
54
- def colorize(fg = :white, *options)
55
- fg_code = 30 + (ANSI_COLORS.index(fg) || 7)
54
+ def colorize(fg = :normal, *options)
55
+ fg_idx = ANSI_COLORS.index(fg)
56
+ fg_code = fg_idx.nil? ? ANSI_MODES.index(fg_idx) : 30 + fg_idx
56
57
  other_codes = options.map do |opt|
57
58
  bg = ANSI_COLORS.index(opt)
58
59
  bg.nil? ? ANSI_MODES.index(opt) : 40 + bg
@@ -116,13 +116,13 @@ module Gyro
116
116
  # rubocop:disable Style/GuardClause
117
117
  if @type == :undefined || @type.empty?
118
118
  msg = %(The attribute "#{@name}" from "#{@entity_name}" has no type - please fix it)
119
- Gyro::Log.fail!(msg, stacktrace: true)
119
+ Gyro::Log.fail!(msg)
120
120
  end
121
121
  if !@json_key_path.empty? && !@enum_values.empty? && (@enum_values.size != @json_values.size)
122
122
  message = %(The attribute "#{@name}" from "#{@entity_name}" is wrongly annotated:) +
123
123
  %(when declaring an type with enum and JSONKeyPath, you must have the same number of items) +
124
124
  %(in the 'enumValues' and 'JSONValues' annotations.)
125
- Gyro::Log.fail!(message, stacktrace: true)
125
+ Gyro::Log.fail!(message)
126
126
  end
127
127
  # rubocop:enable Style/GuardClause
128
128
  end
@@ -18,7 +18,7 @@ module Gyro
18
18
  # One Relationship between attributes in the xcdatamodel
19
19
  #
20
20
  class Relationship
21
- attr_accessor :entity_name, :name, :type, :optional, :deletion_rule
21
+ attr_accessor :entity_name, :name, :type, :optional, :deletion_rule, :comment
22
22
  attr_accessor :inverse_name, :inverse_type, :json_key_path, :support_annotation, :json_ignored
23
23
  attr_accessor :realm_ignored
24
24
  attr_accessor :destination
@@ -38,6 +38,7 @@ module Gyro
38
38
  @realm_ignored = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'realmIgnored').empty? ? false : true
39
39
  @json_ignored = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'JSONIgnored').empty? ? false : true
40
40
  @support_annotation = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'supportAnnotation')
41
+ @comment = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'comment')
41
42
  load_type(relationship_xml)
42
43
  @destination = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'destination')
43
44
  search_for_error
@@ -45,7 +46,7 @@ module Gyro
45
46
 
46
47
  def to_h
47
48
  { 'entity_name' => entity_name, 'name' => name, 'type' => type.to_s,
48
- 'optional' => optional, 'deletion_rule' => deletion_rule,
49
+ 'optional' => optional, 'deletion_rule' => deletion_rule, 'comment' => comment,
49
50
  'inverse_name' => inverse_name, 'inverse_type' => inverse_type,
50
51
  'json_key_path' => json_key_path, 'json_ignored' => json_ignored,
51
52
  'support_annotation' => support_annotation,
@@ -72,12 +73,12 @@ module Gyro
72
73
  # rubocop:disable Style/GuardClause
73
74
  if inverse_type.empty? && destination.empty?
74
75
  message = %(The relationship "#{@name}" from "#{@entity_name}" is wrong - please fix it)
75
- Gyro::Log.fail!(message, stacktrace: true)
76
+ Gyro::Log.fail!(message)
76
77
  end
77
78
  if !destination.empty? && type != :to_many
78
79
  message = %(The relationship "#{@name}" from "#{@entity_name}" is wrong - ) +
79
80
  %(please set a 'No Value' relationship as 'To Many')
80
- Gyro::Log.fail!(message, stacktrace: true)
81
+ Gyro::Log.fail!(message)
81
82
  end
82
83
  # rubocop:enable Style/GuardClause
83
84
  end
@@ -36,12 +36,18 @@ module Gyro
36
36
  attr_accessor :entities
37
37
 
38
38
  def initialize(xcdatamodel_dir)
39
- contents_file = File.join(xcdatamodel_dir, 'contents')
40
- Gyro::Log.fail!('Unable to find contents of xcdatamodel', stacktrace: true) unless File.exist?(contents_file)
39
+ is_xcdatamodeld = xcdatamodel_dir.extname != '.xcdatamodeld'
40
+ Gyro::Log.fail!(%(Please target an '.xcdatamodel' file inside your xcdatamodeld)) unless is_xcdatamodeld
41
+ if xcdatamodel_dir.parent.extname == '.xcdatamodeld'
42
+ xcdatamodeld_info_message = 'You are using an xcdatamodeld, ' \
43
+ 'please be sure you target the correct version of your xcdatamodel.' \
44
+ ' Current version used by gyro is: ' + xcdatamodel_dir.basename.to_path
45
+ Gyro::Log.info(xcdatamodeld_info_message)
46
+ end
47
+ file_contents = xcdatamodel_dir + 'contents'
48
+ Gyro::Log.fail!('Unable to find contents of xcdatamodel') unless file_contents.exist?
41
49
  @entities = {}
42
- file = File.open(contents_file)
43
- document_xml = Document.new(file)
44
- file.close
50
+ document_xml = File.open(file_contents) { |file| Document.new(file) }
45
51
  load_entities(document_xml)
46
52
  end
47
53
 
@@ -12,24 +12,56 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ require 'yaml'
16
+
15
17
  module Gyro
16
18
  # Gyro Template Helper
17
19
  #
18
20
  module Template
21
+ # Print template list representation
22
+ #
19
23
  def self.print_list
20
- Gyro::Template.directory.children.sort_by(&:basename).each do |entry|
21
- alias_name, target = Gyro::Template.resolve_alias(entry)
22
- if alias_name
23
- puts [
24
- ' - '.colorize(:gray, :faint),
25
- alias_name.colorize(:gray),
26
- ' (alias for '.colorize(:gray, :faint),
27
- target.colorize(:gray),
28
- ')'.colorize(:gray, :faint)
29
- ].join
30
- elsif entry.directory?
31
- puts ' - ' + entry.basename.to_s
24
+ directories = Gyro::Template.directory.children.select(&:directory?).map(&:basename).map(&:to_s)
25
+ deprecated = select_deprecated_templates(directories)
26
+ non_deprecated = select_non_deprecated_templates(directories)
27
+ print_templates(non_deprecated.sort + deprecated.sort)
28
+ end
29
+
30
+ # Select deprecated templates from the config file
31
+ #
32
+ # @param [Array<String>] directories
33
+ # The array of directories name
34
+ # @return [Array<String>]
35
+ # The array of deprecated templates
36
+ #
37
+ def self.select_deprecated_templates(directories)
38
+ config['deprecated'].select { |t| config['alias'].key?(t) || directories.include?(t) }
39
+ end
40
+
41
+ # Select non deprecated templates from the template directory and the config file
42
+ #
43
+ # @param [Array<String>] directories
44
+ # The array of directories name
45
+ # @return [Array<String>]
46
+ # The array of non deprecated templates
47
+ #
48
+ def self.select_non_deprecated_templates(directories)
49
+ (directories + config['alias'].keys).reject { |t| config['deprecated'].include?(t) }
50
+ end
51
+
52
+ def self.print_templates(array)
53
+ array.each do |name|
54
+ alias_target = Gyro::Template.resolve_alias(name)
55
+ is_deprecated = config['deprecated'].include?(name)
56
+ txt = [' - ']
57
+ txt << name.colorize(is_deprecated ? :gray : :normal)
58
+ if alias_target
59
+ txt << ' (alias for '.colorize(:gray, :faint)
60
+ txt << alias_target.colorize(:gray)
61
+ txt << ')'.colorize(:gray, :faint)
32
62
  end
63
+ txt << ' (deprecated)'.colorize(:yellow) if is_deprecated
64
+ puts txt.join
33
65
  end
34
66
  end
35
67
 
@@ -50,28 +82,14 @@ module Gyro
50
82
 
51
83
  # @param [Pathname] entry
52
84
  # The alias to resolve
53
- # @return [(String, String)]
54
- # A 2-items array of [the alias name, the alias target name]
85
+ # @return [String]
86
+ # The alias target name
55
87
  # Or nil if the entry does not correspond to a valid template alias
56
88
  #
57
- def self.resolve_alias(entry)
58
- return nil unless entry.exist?
59
- return nil if entry.extname != '.alias'
60
- base = entry.basename('.alias').to_s
61
- target = entry.open(&:readline).chomp # Only read the first line of the file, the rest is ignored
62
- return nil if File.basename(target) != target || target.include?('..') # Security measure
63
- [base, target]
64
- end
65
-
66
- # Resolve alias by name
67
- #
68
- # @return [(String, String)]
69
- # A 2-items array of [the alias name, the alias target name]
70
- # Or nil if the name does not correspond to a valid template alias
71
- #
72
- def self.resolve_alias_name(name)
73
- path = Gyro::Template.directory + (name + '.alias')
74
- resolve_alias(path)
89
+ def self.resolve_alias(name)
90
+ target = config['alias'][name]
91
+ return nil unless target
92
+ target
75
93
  end
76
94
 
77
95
  # @param [String] template_param
@@ -108,9 +126,15 @@ module Gyro
108
126
  # The path to the template corresponding to that name or path
109
127
  #
110
128
  def self.find_by_name(name)
111
- _, target = Gyro::Template.resolve_alias_name(name)
129
+ target = Gyro::Template.resolve_alias(name)
112
130
  template_dir = Gyro::Template.directory + (target || name)
113
131
  return template_dir if template_dir.directory?
114
132
  end
133
+
134
+ # Hash of Yaml config for templates
135
+ #
136
+ def self.config
137
+ @config ||= YAML.load_file(Gyro::Template.directory + 'config.yml')
138
+ end
115
139
  end
116
140
  end
@@ -15,5 +15,5 @@
15
15
  # Gyro Version
16
16
  #
17
17
  module Gyro
18
- VERSION = '1.4.0'.freeze
18
+ VERSION = '1.5.0'.freeze
19
19
  end
@@ -8,13 +8,15 @@
8
8
 
9
9
  If you want to use this template you need to work with `Realm`.
10
10
 
11
- # Characteristics
11
+ # Customization
12
12
 
13
- In this template you have additional parameters to inject constants :
13
+ You can use the following parameters to inject custom values to this template (using `--param KEY:VALUE` on the command line):
14
14
 
15
- - package (ex : **com.gyro.model.realm**)
16
- - 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)
17
- - support_annotations (you can define annotation for properties ex : **@android.support.annotation.IntRange(from=0,to=255)** or **@android.support.annotation.Nullable**)
15
+ | Parameter Key | Description |
16
+ |---------------|-------------|
17
+ | `package` | The Android package in which the generated files will be generated (e.g. "`com.gyro.model.realm`") |
18
+ | `use_wrappers` | Define this to `true` if you want to use wrapper types (e.g. `Boolean`) instead of primitive types (e.g. `boolean`) when your attribute is **optional** inside xcdatamodel |
19
+ | `support_annotations` | Define this to `true` to generate `@android.support.annotation`s for properties (e.g. `@android.support.annotation.IntRange(from=0,to=255)`, `@android.support.annotation.Nullable`, etc) |
18
20
 
19
21
  # Usage
20
22
 
@@ -161,4 +163,4 @@ public class Product extends RealmObject {
161
163
  this.price = price;
162
164
  }
163
165
  }
164
- ```
166
+ ```
@@ -3,6 +3,9 @@
3
3
  public static final class Relationships {
4
4
  {%- for relationship in entity.relationships -%}
5
5
  {%- if relationship.inverse == false %}
6
+ {%- if relationship.comment.size > 0 %}
7
+ // {{ relationship.comment }}
8
+ {%- endif %}
6
9
  public static final String {{ relationship.name | snake_case | upcase }} = "{{ relationship.name }}";
7
10
  {%- endif -%}
8
11
  {%- endfor %}
@@ -8,11 +8,13 @@
8
8
 
9
9
  If you want to use this template you need to work with `Realm`.
10
10
 
11
- # Characteristics
11
+ # Customization
12
12
 
13
- In this template you have additional parameters to inject constants :
13
+ You can use the following parameters to inject custom values to this template (using `--param KEY:VALUE` on the command line):
14
14
 
15
- - package (ex : **com.gyro.model.realm**)
15
+ | Parameter Key | Description |
16
+ |---------------|-------------|
17
+ | `package` | The Android package in which the generated files will be generated (e.g. "`com.gyro.model.realm`") |
16
18
 
17
19
  # Usage
18
20
 
@@ -35,20 +37,20 @@ package com.gyro.model.realm
35
37
 
36
38
  import io.realm.RealmObject
37
39
 
38
- class FidelityCard: RealmObject() {
40
+ open class FidelityCard: RealmObject() {
39
41
 
40
42
  object Attributes {
41
- const val IDENTIFIER: String = "identifier";
42
- const val POINTS: String = "points";
43
+ const val IDENTIFIER: String = "identifier"
44
+ const val POINTS: String = "points"
43
45
  }
44
46
 
45
47
  object Relationships {
46
- const val USER: String = "user";
48
+ const val USER: String = "user"
47
49
  }
48
50
 
49
- private var identifier: Short = 0;
50
- private var points: Integer = 0;
51
- private var user: User? = null;
51
+ private var identifier: Short = 0
52
+ private var points: Integer = 0
53
+ private var user: User? = null
52
54
  }
53
55
  ```
54
56
 
@@ -21,7 +21,7 @@ enum class {{ attribute.enum_type }}(val jsonValue: String) {
21
21
 
22
22
  companion object {
23
23
  @JvmStatic
24
- fun get(jsonValue: String): {{ attribute.enum_type }}? {
24
+ fun get(jsonValue: String?): {{ attribute.enum_type }}? {
25
25
  return {{ attribute.enum_type }}.values().firstOrNull { it.jsonValue == jsonValue }
26
26
  }
27
27
  }
@@ -3,6 +3,9 @@
3
3
  object Relationships {
4
4
  {%- for relationship in entity.relationships -%}
5
5
  {%- if relationship.inverse == false %}
6
+ {%- if relationship.comment.size > 0 %}
7
+ // {{ relationship.comment }}
8
+ {%- endif %}
6
9
  const val {{ relationship.name | snake_case | upcase }}: String = "{{ relationship.name }}"
7
10
  {%- endif -%}
8
11
  {%- endfor %}
@@ -0,0 +1,25 @@
1
+ alias:
2
+ # The template named 'android-java' was originally just named `android`
3
+ # and was written in Java before Kotlin even existed.
4
+ #
5
+ # So this alias exists mainly for compatibility reasons, so that people
6
+ # who used `-t android` in previous versions of `gyro` can still continue
7
+ # to do so and that this new update of gyro doesn't break their setup.
8
+ android: android-java
9
+ # The template named 'anviking-decodable' was originally just named 'decodable'
10
+ # as it was made to generate JSON parsing code using the Anviking/Decodable pod.
11
+ #
12
+ # But now that Swift 4 has protocol Decodable, this template name is confusing,
13
+ # so we decided to rename it anviking-decodable and deprecate the old name,
14
+ # so that when we have time to create a template for Swift 4's Codable there
15
+ # won't be any risk of confusion.
16
+ decodable: anviking-decodable
17
+ # It happens that the `swift3` template is also compatible with Swift 4 without any change.
18
+ # So we can use the same template for both Swift 3 and Swift 4
19
+ swift4: swift3
20
+ deprecated:
21
+ - object-mapper
22
+ - swift3-variant
23
+ - android # renamed android-java
24
+ - decodable # renamed anviking-decodable
25
+
@@ -10,9 +10,11 @@
10
10
 
11
11
  When you need to work with `ObjectMapper` and `Realm` together
12
12
 
13
- # Characteristics
13
+ # Description
14
14
 
15
- In this template optional Realm objects (Attributes - RealmOptional - or Relationships - List<> -) are var properties :
15
+ In this template optional Realm objects (Attributes - RealmOptional - or Relationships - List<> -) are var properties.
16
+
17
+ This is not recommanded by Realm, and not conform to the Realm documentation (and can lead to bad behaviors with Realm if you happen to affect a new `List` or `RealmOptional` instance to those properties) but sadly this is required to work with the deprecated `ObjectMapper` template.
16
18
 
17
19
  ```
18
20
  // Attribute generation
@@ -32,8 +34,6 @@ In this template optional Realm objects (Attributes - RealmOptional - or Relatio
32
34
  {%- endif %}
33
35
  ```
34
36
 
35
- This is not recommanded by Realm, and not conform to the Realm documentation (and can lead to bad behaviors with Realm if you happen to affect a new `List` or `RealmOptional` instance to those properties) but sadly this is required to work with the deprecated `ObjectMapper` template.
36
-
37
37
  # Generated Code
38
38
 
39
39
  `Product.swift`
@@ -60,4 +60,4 @@ final class Product: Object {
60
60
  var users = List<Users>()
61
61
  }
62
62
 
63
- ```
63
+ ```
@@ -3,6 +3,9 @@
3
3
  import RealmSwift
4
4
  import Foundation
5
5
 
6
+ {% if entity.comment.size > 0 -%}
7
+ /// {{ entity.comment }}
8
+ {% endif -%}
6
9
  final class {{ entity.name }}: Object {
7
10
  {%- include 'inc/attributes_enum' -%}
8
11
  {% include 'inc/relationships_enum' -%}
@@ -4,7 +4,7 @@
4
4
  {%- for attribute in entity.attributes -%}
5
5
  {%- if attribute.realm_ignored or attribute.realm_read_only.size == 0 -%}
6
6
  {%- if attribute.comment.size > 0 %}
7
- /** {{ attribute.comment }} **/
7
+ /// {{ attribute.comment }}
8
8
  {%- endif %}
9
9
  case {{ attribute.name }} = "{{ attribute.name | escape_quotes }}"
10
10
  {%- endif %}
@@ -11,6 +11,9 @@
11
11
  {%- endif -%}
12
12
  {%- endcapture -%}
13
13
  {%- assign relationship_name = relationship_name %}
14
+ {%- if relationship.comment.size > 0 %}
15
+ /// {{ relationship.comment }}
16
+ {%- endif %}
14
17
  case {{ relationship_name | uncapitalize }} = "{{ relationship_name | escape_quotes }}"
15
18
  {%- endfor %}
16
19
  }
@@ -11,9 +11,17 @@
11
11
  This template is the reference for swift 3 with Realm generation code. This template is compatible with swift 4.
12
12
  You can use it when you need to work with `Realm`
13
13
 
14
- # Characteristics
14
+ # Customization
15
15
 
16
- In this template optional Realm objects (Attributes - RealmOptional - or Relationships - List<> -) are `let` properties (conform to the Realm documentation) :
16
+ You can use the following parameters to inject custom values to this template (using `--param KEY:VALUE` on the command line):
17
+
18
+ | Parameter Key | Description |
19
+ |---------------|-------------|
20
+ | `public` | If set to true, every generated model and properties will be declared `public`. Otherwise it will not be annotated with access scope keyword, so will default to `internal` |
21
+
22
+ # Description
23
+
24
+ In this template, optional Realm objects (Attributes - RealmOptional - or Relationships - List<> -) are `let` properties (which is conform to the Realm documentation). This is the template to use when you use RealmSwift.
17
25
 
18
26
  ```
19
27
  // Attribute generation
@@ -3,7 +3,7 @@
3
3
  import RealmSwift
4
4
  import Foundation
5
5
 
6
- final class {{ entity.name }}: Object {
6
+ {% if params.public %}public {% endif %}final class {{ entity.name }}: Object {
7
7
  {%- include 'inc/attributes_enum' -%}
8
8
  {% include 'inc/relationships_enum' -%}
9
9
  {% include 'inc/attributes_properties' %}
@@ -1,7 +1,7 @@
1
1
  {%- if attribute.enum_type.size > 0 -%}
2
2
  /* DO NOT EDIT | Generated by gyro */
3
3
 
4
- enum {{ params.prefix }}{{ attribute.enum_type }}: String {
4
+ {% if params.public %}public {% endif %}enum {{ params.prefix }}{{ attribute.enum_type }}: String {
5
5
  {%- for value in attribute.enum_values %}
6
6
  {%- if attribute.enum_values.size > 0 %}
7
7
  {% assign jsonKey = value -%}
@@ -1,6 +1,6 @@
1
1
 
2
2
  {% if entity.attributes.size > 0 %}
3
- enum Attributes: String {
3
+ {% if params.public %}public {% endif %}enum Attributes: String {
4
4
  {%- for attribute in entity.attributes -%}
5
5
  {%- if attribute.realm_ignored or attribute.realm_read_only.size == 0 -%}
6
6
  {%- if attribute.comment.size > 0 %}
@@ -18,7 +18,7 @@
18
18
  {%- include 'inc/optional_attribute_property' -%}
19
19
  {%- else -%}
20
20
  {%- comment -%} ******* GENERATE DEFAULT ATTRIBUTE PROPERTY ******* {% endcomment %}
21
- @objc dynamic var {{ attribute.name }}: {{ convert_type }} = {{ default_value }} {%- if attribute.name == entity.identity_attribute %} /* Primary Key */{% endif -%}
21
+ @objc {% if params.public %}public {% endif %}dynamic var {{ attribute.name }}: {{ convert_type }} = {{ default_value }} {%- if attribute.name == entity.identity_attribute %} /* Primary Key */{% endif -%}
22
22
  {%- endif -%}{%- endif -%}
23
23
  {%- endif -%}
24
24
  {%- endfor -%}
@@ -1,13 +1,13 @@
1
1
  {%- if attribute.optional == true %}
2
2
 
3
- @objc dynamic var {{ attribute.name }}: String?
3
+ @objc {% if params.public %}public {% endif %}dynamic var {{ attribute.name }}: String?
4
4
  {%- else %}
5
5
 
6
- @objc dynamic var {{ attribute.name }}: String = ""
6
+ @objc {% if params.public %}public {% endif %}dynamic var {{ attribute.name }}: String = ""
7
7
  {%- endif %}
8
8
  {%- assign enum_type = attribute.enum_type %}
9
9
  {%- assign enum_name = attribute.name %}
10
- var {{ enum_name }}Enum: {{ enum_type | delete_objc_prefix }}? {
10
+ {% if params.public %}public {% endif %}var {{ enum_name }}Enum: {{ enum_type | delete_objc_prefix }}? {
11
11
  get {
12
12
  {%- if attribute.optional == true %}
13
13
  guard let {{ attribute.name }} = {{ attribute.name }},
@@ -1,6 +1,6 @@
1
1
  {%- if entity.has_ignored == true %}
2
2
  // Specify properties to ignore (Realm won't persist these)
3
- override static func ignoredProperties() -> [String] {
3
+ override {% if params.public %}public {% endif %}static func ignoredProperties() -> [String] {
4
4
  return [
5
5
  {%- capture enum_ignored_properties -%}
6
6
  {%- for attribute in entity.attributes -%}
@@ -1,6 +1,6 @@
1
1
  {%- if entity.has_indexed_attributes == true %}
2
2
  // Specify properties to index
3
- override static func indexedProperties() -> [String] {
3
+ override {% if params.public %}public {% endif %}static func indexedProperties() -> [String] {
4
4
  return [
5
5
  {%- capture enum_indexed_properties -%}
6
6
  {%- for attribute in entity.attributes -%}
@@ -2,10 +2,10 @@
2
2
  {%- if relationship.inverse == true %}
3
3
  {% assign name_size = relationship.name | size | minus: 1 %}
4
4
  {%- if relationship.type == "to_many" %}
5
- let {{ relationship.name | truncate: name_size, '' }}s = LinkingObjects(fromType: {{ relationship.inverse_type }}.self, property: "{{ relationship.inverse_name }}")
5
+ {% if params.public %}public {% endif %}let {{ relationship.name | truncate: name_size, '' }}s = LinkingObjects(fromType: {{ relationship.inverse_type }}.self, property: "{{ relationship.inverse_name }}")
6
6
  {%- else %}
7
- let {{ relationship.name | truncate: name_size, '' }}s = LinkingObjects(fromType: {{ relationship.inverse_type }}.self, property: "{{ relationship.inverse_name }}")
8
- var {{ relationship.name | truncate: name_size, '' }}: {{ relationship.inverse_type }}? { return {{ relationship.name | truncate: name_size, '' }}s.first }
7
+ {% if params.public %}public {% endif %}let {{ relationship.name | truncate: name_size, '' }}s = LinkingObjects(fromType: {{ relationship.inverse_type }}.self, property: "{{ relationship.inverse_name }}")
8
+ {% if params.public %}public {% endif %}var {{ relationship.name | truncate: name_size, '' }}: {{ relationship.inverse_type }}? { return {{ relationship.name | truncate: name_size, '' }}s.first }
9
9
  {%- endif -%}
10
10
  {%- endif -%}
11
11
  {%- endfor -%}
@@ -1,5 +1,5 @@
1
1
  {%- if attribute.is_number == true or attribute.is_bool == true %}
2
- let {{ attribute.name }} = RealmOptional<{{ convert_type }}>(){%- if attribute.name == entity.identity_attribute %} /* Primary Key */{% endif -%}
2
+ {% if params.public %}public {% endif %}let {{ attribute.name }} = RealmOptional<{{ convert_type }}>(){%- if attribute.name == entity.identity_attribute %} /* Primary Key */{% endif -%}
3
3
  {%- else %}
4
- @objc dynamic var {{ attribute.name }}: {{ convert_type }}?{%- if attribute.name == entity.identity_attribute %} /* Primary Key */{% endif -%}
4
+ @objc {% if params.public %}public {% endif %}dynamic var {{ attribute.name }}: {{ convert_type }}?{%- if attribute.name == entity.identity_attribute %} /* Primary Key */{% endif -%}
5
5
  {%- endif -%}
@@ -1,5 +1,5 @@
1
1
  {%- if entity.has_primary_key == true %}
2
- override static func primaryKey() -> String? {
2
+ override {% if params.public %}public {% endif %}static func primaryKey() -> String? {
3
3
  return "{{ entity.identity_attribute }}"
4
4
  }
5
5
  {% endif -%}
@@ -1,9 +1,9 @@
1
1
  {%- for relationship in entity.relationships -%}
2
2
  {%- if relationship.inverse == false %}
3
3
  {%- if relationship.type == "to_many" %}
4
- let {{ relationship.name }} = List<{{ relationship.inverse_type }}>()
4
+ {% if params.public %}public {% endif %}let {{ relationship.name }} = List<{{ relationship.inverse_type }}>()
5
5
  {%- else %}
6
- @objc dynamic var {{ relationship.name }}: {{ relationship.inverse_type }}?
6
+ @objc {% if params.public %}public {% endif %}dynamic var {{ relationship.name }}: {{ relationship.inverse_type }}?
7
7
  {%- endif %}
8
8
  {%- endif %}
9
9
  {%- endfor -%}
@@ -1,5 +1,5 @@
1
1
  {%- if entity.relationships.size > 0 and entity.has_only_inverse == false %}
2
- enum Relationships: String {
2
+ {% if params.public %}public {% endif %}enum Relationships: String {
3
3
  {%- for relationship in entity.relationships %}
4
4
  {%- capture relationship_name -%}
5
5
  {%- if relationship.inverse == true -%}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gyro
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - NijiDigital
@@ -109,12 +109,12 @@ files:
109
109
  - lib/templates/android-kotlin/inc/_type_converter.liquid
110
110
  - lib/templates/android-kotlin/inc/_type_defaults.liquid
111
111
  - lib/templates/android-kotlin/inc/_type_primitives.liquid
112
- - lib/templates/android.alias
113
- - lib/templates/decodable/README.md
114
- - lib/templates/decodable/entity.liquid
115
- - lib/templates/decodable/entity_filename.liquid
116
- - lib/templates/decodable/enum.liquid
117
- - lib/templates/decodable/enum_filename.liquid
112
+ - lib/templates/anviking-decodable/README.md
113
+ - lib/templates/anviking-decodable/entity.liquid
114
+ - lib/templates/anviking-decodable/entity_filename.liquid
115
+ - lib/templates/anviking-decodable/enum.liquid
116
+ - lib/templates/anviking-decodable/enum_filename.liquid
117
+ - lib/templates/config.yml
118
118
  - lib/templates/object-mapper/README.md
119
119
  - lib/templates/object-mapper/entity.liquid
120
120
  - lib/templates/object-mapper/entity_filename.liquid
@@ -154,7 +154,6 @@ files:
154
154
  - lib/templates/swift3/inc/_relationship_properties.liquid
155
155
  - lib/templates/swift3/inc/_relationships_enum.liquid
156
156
  - lib/templates/swift3/inc/_type_converter.liquid
157
- - lib/templates/swift4.alias
158
157
  homepage: https://github.com/NijiDigital/gyro
159
158
  licenses:
160
159
  - Apache-2.0
@@ -1,10 +0,0 @@
1
- android-java
2
-
3
- === Note ===
4
-
5
- The template named 'android-java' was originally just named `android`
6
- and was written in Java before Kotlin even existed.
7
-
8
- So this alias exists mainly for compatibility reasons, so that people
9
- who used `-t android` in previous versions of `gyro` can still continue
10
- to do so and that this new update of gyro doesn't break their setup.
@@ -1,6 +0,0 @@
1
- swift3
2
-
3
- === Note ===
4
-
5
- It happens that the `swift3` template is also compatible with Swift 4 without any change.
6
- So we can use the same template for both Swift 3 and Swift 4