gyro 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +42 -797
  3. data/bin/gyro +91 -84
  4. data/documentation/enum.png +0 -0
  5. data/documentation/enum_json.png +0 -0
  6. data/documentation/ignored.png +0 -0
  7. data/documentation/json.png +0 -0
  8. data/documentation/primary_key.png +0 -0
  9. data/documentation/read_only.png +0 -0
  10. data/documentation/simple_entity.png +0 -0
  11. data/documentation/support_annotation.png +0 -0
  12. data/documentation/transformer.png +0 -0
  13. data/documentation/transformers.png +0 -0
  14. data/lib/gyro.rb +18 -29
  15. data/lib/gyro/generator/json.rb +30 -0
  16. data/lib/gyro/generator/liquid.rb +22 -0
  17. data/lib/gyro/generator/liquid/filters.rb +53 -0
  18. data/lib/gyro/generator/liquid/liquid.rb +124 -0
  19. data/lib/gyro/generator/liquid/whitespace_patch.rb +61 -0
  20. data/lib/gyro/log.rb +46 -0
  21. data/lib/gyro/parser/xcdatamodel.rb +20 -0
  22. data/lib/gyro/parser/xcdatamodel/attribute.rb +129 -0
  23. data/lib/gyro/parser/xcdatamodel/entity.rb +195 -0
  24. data/lib/gyro/parser/xcdatamodel/relationship.rb +84 -0
  25. data/lib/gyro/parser/xcdatamodel/xcdatamodel.rb +65 -0
  26. data/lib/gyro/template.rb +68 -0
  27. data/lib/gyro/version.rb +19 -0
  28. data/lib/templates/android/README.md +164 -0
  29. data/lib/templates/android/entity.liquid +49 -0
  30. data/lib/templates/android/entity_filename.liquid +1 -0
  31. data/lib/templates/android/enum.liquid +44 -0
  32. data/lib/templates/android/enum_filename.liquid +1 -0
  33. data/lib/templates/android/inc/_attributes_enum.liquid +17 -0
  34. data/lib/templates/android/inc/_attributes_getter_setter.liquid +58 -0
  35. data/lib/templates/android/inc/_attributes_properties.liquid +35 -0
  36. data/lib/templates/android/inc/_enum_getter_setter.liquid +19 -0
  37. data/lib/templates/android/inc/_primitives.liquid +30 -0
  38. data/lib/templates/android/inc/_relationships_enum.liquid +14 -0
  39. data/lib/templates/android/inc/_relationships_getter_setter.liquid +47 -0
  40. data/lib/templates/android/inc/_relationships_properties.liquid +27 -0
  41. data/lib/templates/android/inc/_type_converter.liquid +22 -0
  42. data/lib/templates/android/inc/_wrapper_type_converter.liquid +22 -0
  43. data/lib/templates/decodable/README.md +34 -0
  44. data/lib/templates/decodable/entity.liquid +57 -0
  45. data/lib/templates/decodable/entity_filename.liquid +1 -0
  46. data/lib/templates/decodable/enum.liquid +0 -0
  47. data/lib/templates/decodable/enum_filename.liquid +0 -0
  48. data/lib/templates/object-mapper/README.md +40 -0
  49. data/lib/templates/object-mapper/entity.liquid +66 -0
  50. data/lib/templates/object-mapper/entity_filename.liquid +1 -0
  51. data/lib/templates/object-mapper/enum.liquid +0 -0
  52. data/lib/templates/object-mapper/enum_filename.liquid +0 -0
  53. data/lib/templates/swift3-variant/README.md +60 -0
  54. data/lib/templates/swift3-variant/entity.liquid +12 -0
  55. data/lib/templates/swift3-variant/entity_filename.liquid +1 -0
  56. data/lib/templates/swift3-variant/enum.liquid +15 -0
  57. data/lib/templates/swift3-variant/enum_filename.liquid +1 -0
  58. data/lib/templates/swift3-variant/inc/_attributes_enum.liquid +13 -0
  59. data/lib/templates/swift3-variant/inc/_attributes_properties.liquid +32 -0
  60. data/lib/templates/swift3-variant/inc/_default_value_converter.liquid +14 -0
  61. data/lib/templates/swift3-variant/inc/_enum_attribute_property.liquid +26 -0
  62. data/lib/templates/swift3-variant/inc/_ignored_properties.liquid +24 -0
  63. data/lib/templates/swift3-variant/inc/_indexed_properties.liquid +19 -0
  64. data/lib/templates/swift3-variant/inc/_inverse_properties.liquid +11 -0
  65. data/lib/templates/swift3-variant/inc/_optional_attribute_property.liquid +5 -0
  66. data/lib/templates/swift3-variant/inc/_primary_key.liquid +5 -0
  67. data/lib/templates/swift3-variant/inc/_relationship_properties.liquid +9 -0
  68. data/lib/templates/swift3-variant/inc/_relationships_enum.liquid +17 -0
  69. data/lib/templates/swift3-variant/inc/_type_converter.liquid +20 -0
  70. data/lib/templates/swift3/README.md +60 -0
  71. data/lib/templates/swift3/entity.liquid +12 -0
  72. data/lib/templates/swift3/entity_filename.liquid +1 -0
  73. data/lib/templates/swift3/enum.liquid +15 -0
  74. data/lib/templates/swift3/enum_filename.liquid +1 -0
  75. data/lib/templates/swift3/inc/_attributes_enum.liquid +13 -0
  76. data/lib/templates/swift3/inc/_attributes_properties.liquid +32 -0
  77. data/lib/templates/swift3/inc/_default_value_converter.liquid +14 -0
  78. data/lib/templates/swift3/inc/_enum_attribute_property.liquid +26 -0
  79. data/lib/templates/swift3/inc/_ignored_properties.liquid +24 -0
  80. data/lib/templates/swift3/inc/_indexed_properties.liquid +19 -0
  81. data/lib/templates/swift3/inc/_inverse_properties.liquid +11 -0
  82. data/lib/templates/swift3/inc/_optional_attribute_property.liquid +5 -0
  83. data/lib/templates/swift3/inc/_primary_key.liquid +5 -0
  84. data/lib/templates/swift3/inc/_relationship_properties.liquid +9 -0
  85. data/lib/templates/swift3/inc/_relationships_enum.liquid +17 -0
  86. data/lib/templates/swift3/inc/_type_converter.liquid +20 -0
  87. metadata +134 -31
  88. data/lib/gyro/realm/java/converter.rb +0 -63
  89. data/lib/gyro/realm/java/enum_generator.rb +0 -128
  90. data/lib/gyro/realm/java/generator.rb +0 -183
  91. data/lib/gyro/realm/java/templates.rb +0 -67
  92. data/lib/gyro/realm/objc/converter.rb +0 -63
  93. data/lib/gyro/realm/objc/enum_generator.rb +0 -86
  94. data/lib/gyro/realm/objc/generator.rb +0 -373
  95. data/lib/gyro/realm/objc/json_category_generator.rb +0 -172
  96. data/lib/gyro/realm/objc/protocol_generator.rb +0 -59
  97. data/lib/gyro/realm/objc/templates.rb +0 -100
  98. data/lib/gyro/realm/swift/converter.rb +0 -74
  99. data/lib/gyro/realm/swift/enum_generator.rb +0 -73
  100. data/lib/gyro/realm/swift/generator.rb +0 -265
  101. data/lib/gyro/realm/swift/object_mapper_generator.rb +0 -124
  102. data/lib/gyro/realm/swift/templates.rb +0 -64
  103. data/lib/gyro/utils/file_utils.rb +0 -31
  104. data/lib/gyro/utils/log.rb +0 -68
  105. data/lib/gyro/utils/raise.rb +0 -23
  106. data/lib/gyro/utils/string_xcdatamodel.rb +0 -58
  107. data/lib/gyro/xcdatamodel/parser/attribute.rb +0 -98
  108. data/lib/gyro/xcdatamodel/parser/entity.rb +0 -234
  109. data/lib/gyro/xcdatamodel/parser/relationship.rb +0 -70
  110. data/lib/gyro/xcdatamodel/parser/xcdatamodel.rb +0 -59
@@ -1,124 +0,0 @@
1
- =begin
2
- Copyright 2016 - Niji
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- =end
16
-
17
- require File.expand_path('templates', File.dirname(__FILE__))
18
- require File.expand_path('../../utils/file_utils', File.dirname(__FILE__))
19
- require File.expand_path('../../utils/string_xcdatamodel', File.dirname(__FILE__))
20
-
21
- module Gyro
22
- module Realm
23
- module Swift
24
- module ObjectMapperGenerator
25
-
26
- # INCLUDES #############################################################
27
-
28
- include Templates
29
-
30
- # PUBLIC METHODS #######################################################
31
-
32
- def generate_object_mapper_categories(path, xcdatamodel, framework = false)
33
- json_path = File.join(path, 'ObjectMapper')
34
- Dir.mkdir(json_path) unless Dir.exists?(json_path)
35
- xcdatamodel.entities.each do |_, entity|
36
- generate_json_category_file(json_path, entity, framework)
37
- end
38
- end
39
-
40
- # PRIVATE METHODS #######################################################
41
-
42
- def generate_json_category_file(path, entity, framework)
43
- if !entity.attributes.empty? || !entity.relationships.empty?
44
- source_file = generate_source_extension_file(entity)
45
- file_name = EXTENSION_NAME%[entity.name]
46
- Gyro.write_file_with_name(path, SOURCE_TEMPLATE%[file_name], source_file) unless source_file.empty?
47
- end
48
- end
49
-
50
- def generate_source_extension_file(entity)
51
- source_file = String.new
52
- source_file << GENERATED_MESSAGE + "\n\n"
53
- source_file << IMPORT_OBJECT_MAPPER + "\n\n"
54
- source_file << EXTENSION_TEMPLATE%[entity.name, "Mappable"] + "\n\n"
55
- source_file << generate_init
56
- source_file << generate_mapping(entity)
57
- source_file << "}\n"
58
- source_file
59
- end
60
-
61
- def generate_mapping(entity)
62
- source_file = String.new
63
- source_file << " // MARK: Mappable\n\n"
64
- source_file << " func mapping(map: Map) {\n"
65
- source_file << generate_mapper_attributes(entity) if !entity.attributes.empty?
66
- source_file << generate_mapper_relationships(entity) if !entity.relationships.empty?
67
- source_file << " }\n"
68
- source_file
69
- end
70
-
71
- def generate_init()
72
- source_file = String.new
73
- source_file << " // MARK: Initializers\n\n"
74
- source_file << " convenience init?(_ map: Map) {\n"
75
- source_file << " self.init()\n"
76
- source_file << " }\n\n"
77
- source_file
78
- end
79
-
80
- def generate_mapper_attributes(entity)
81
- attributes = String.new
82
- attributes << "\n // MARK: Attributes\n"
83
- entity.attributes.each do |_, attribute|
84
- attrKey = attribute.json_key_path.empty? ? attribute.name : attribute.json_key_path
85
- case
86
- when attribute.type == :date
87
- transformer = attribute.transformer.empty? ? "ISO8601DateTransform" : attribute.transformer
88
- attributes << " self." + attribute.name + " <- (map[" + attrKey.add_quotes + "], " + transformer + "())\n"
89
- when attribute.type == :integer_16 && attribute.optional && attribute.enum_type == ""
90
- attributes << " self." + attribute.name + " <- (map[" + attrKey.add_quotes + "], RealmOptionalInt16Transform())\n"
91
- when attribute.type == :integer_32 && attribute.optional
92
- attributes << " self." + attribute.name + " <- (map[" + attrKey.add_quotes + "], RealmOptionalInt32Transform())\n"
93
- when attribute.type == :integer_64 && attribute.optional
94
- attributes << " self." + attribute.name + " <- (map[" + attrKey.add_quotes + "], RealmOptionalInt64Transform())\n"
95
- when attribute.type == :float && attribute.optional
96
- attributes << " self." + attribute.name + " <- (map[" + attrKey.add_quotes + "], RealmOptionalFloatTransform())\n"
97
- when attribute.type == :double && attribute.optional
98
- attributes << " self." + attribute.name + " <- (map[" + attrKey.add_quotes + "], RealmOptionalDoubleTransform())\n"
99
- when
100
- attributes << " self." + attribute.name + " <- map[" + attrKey.add_quotes + "]\n"
101
- end
102
- end
103
- attributes
104
- end
105
-
106
- def generate_mapper_relationships(entity)
107
- relationships = String.new
108
- relationships << "\n // MARK: Relationships\n"
109
- entity.relationships.each do |_, relationship|
110
- next if relationship.inverse?
111
- relationKey = relationship.json_key_path.empty? ? relationship.name : relationship.json_key_path
112
- if relationship.type == :to_many
113
- relationships << " self." + relationship.name + " <- (map[" + relationKey.add_quotes + "], ListTransform<" + relationship.inverse_type + ">())\n"
114
- else
115
- relationships << " self." + relationship.name + " <- map[" + relationKey.add_quotes + "]\n"
116
- end
117
- end
118
- relationships
119
- end
120
-
121
- end
122
- end
123
- end
124
- end
@@ -1,64 +0,0 @@
1
- =begin
2
- Copyright 2016 - Niji
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- =end
16
-
17
- module Gyro
18
- module Realm
19
- module Swift
20
- module Templates
21
-
22
- # COMMONS
23
- GENERATED_MESSAGE = '/* DO NOT EDIT | Generated by gyro */'
24
-
25
- # IMPORTS
26
- IMPORT_REALM = 'import RealmSwift'
27
- SWIFT_FILE_TEMPLATE = '%s.swift'
28
- IMPORT_OBJECT_MAPPER = 'import ObjectMapper'
29
-
30
- # ENUM
31
- ENUM_STRING_DEF_TEMPLATE = 'enum %s: String {'
32
- ENUM_STRING_CASE_TEMPLATE = 'case %s = "%s"'
33
-
34
- # CLASS
35
- ARRAY_TEMPLATE ='%s, '
36
- CLASS_TEMPLATE = 'final class %s: Object {'
37
- PROPERTY_DEFAULT_TEMPLATE = 'dynamic var %s: %s = %s'
38
- PROPERTY_OBJECT_TEMPLATE = 'dynamic var %s: %s?'
39
- PROPERTY_LIST_TEMPLATE = 'let %s = List<%s>()'
40
- PROPERTY_LIST_VAR_TEMPLATE = 'var %s = List<%s>()'
41
- PROPERTY_PRIVATE_ENUM_TEMPLATE = 'private dynamic var %s: String?'
42
- PROPERTY_ENUM_TEMPLATE = 'dynamic var %s: String = ""'
43
- PROPERTY_OPTIONAL_ENUM_TEMPLATE = 'dynamic var %s: String? = nil'
44
- PROPERTY_COMPUTED_TEMPLATE = 'var %s: %s {'
45
- PROPERTY_OPTIONAL_COMPUTED_TEMPLATE = 'var %s: %s? {'
46
- PROPERTY_INVERSE_ONE_TEMPLATE = 'var %s: %s? { return %s.first }'
47
- PROPERTY_INVERSE_MANY_TEMPLATE = 'let %s = LinkingObjects(fromType: %s.self, property: "%s")'
48
- PROPERTY_OPTIONAL_NON_NUMBER_TEMPLATE = 'dynamic var %s: %s? = nil'
49
- PROPERTY_OPTIONAL_NUMBER_TEMPLATE = 'let %s = RealmOptional<%s>()'
50
- PROPERTY_OPTIONAL_NUMBER_VAR_TEMPLATE = 'var %s = RealmOptional<%s>()'
51
-
52
- # EXTENSION
53
- EXTENSION_TEMPLATE = 'extension %s: %s {'
54
- EXTENSION_NAME = '%sMapper'
55
- SOURCE_TEMPLATE = '%s.swift'
56
-
57
- # COMMENTS
58
- CLASS_COMMENT_TEMPLATE = "/**\n * %s\n */"
59
- ATTRIBUTE_COMMENT_TEMPLATE = '/** %s */'
60
-
61
- end
62
- end
63
- end
64
- end
@@ -1,31 +0,0 @@
1
- =begin
2
- Copyright 2016 - Niji
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- =end
16
-
17
- module Gyro
18
-
19
- def self.find_xcdatamodel(dir)
20
- Dir.chdir(dir) do
21
- files = Dir.glob('*.xcdatamodel')
22
- files.first.nil? ? nil : File.expand_path(files.first, dir)
23
- end
24
- end
25
-
26
- def self.write_file_with_name(dir, name_file, content)
27
- file_path = File.expand_path(name_file, dir)
28
- File.write(file_path, content)
29
- end
30
-
31
- end
@@ -1,68 +0,0 @@
1
- =begin
2
- Copyright 2016 - Niji
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- =end
16
-
17
- module Gyro
18
- module Log
19
-
20
- def self.title(str) # bg yellow
21
- puts "\e[44;37m#{str}\e[0m"
22
- end
23
-
24
- def self.error(str)
25
- puts "\e[1;31m! #{str}\e[0m"
26
- end
27
-
28
- def self.info(str)
29
- puts "\e[1;33m> #{str}\e[0m"
30
- end
31
-
32
- def self.success(str)
33
- puts "\e[1;32m√ #{str}\e[0m"
34
- end
35
-
36
- def self.prompt(str, url = nil)
37
- prompt = "\e[1;36m ! #{str} [y/n]?\e[0m "
38
- url_info = ' '*10 + "\e[0;37m (use '?' to show in browser)\e[0m"
39
- print prompt
40
- print "#{url_info}\r#{prompt}" if url
41
-
42
- answer = get_char do |c|
43
- `open '#{url}'` if url && (c == '?')
44
- "yn\003".include?(c.downcase) # \003 = ctrl-C
45
- end
46
- puts answer + (url ? ' '*url_info.length : '')
47
- answer.downcase == 'y'
48
- end
49
-
50
- private ######################################################################
51
-
52
- def self.get_char
53
- stop = false
54
- typed_char = ''
55
- begin
56
- system('stty raw -echo')
57
- until stop
58
- typed_char = STDIN.getc.chr
59
- stop = yield typed_char
60
- end
61
- ensure
62
- system('stty -raw echo')
63
- end
64
- typed_char
65
- end
66
-
67
- end
68
- end
@@ -1,23 +0,0 @@
1
- =begin
2
- Copyright 2016 - Niji
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- =end
16
-
17
- module Raise
18
-
19
- def self.error(str)
20
- raise "\e[1;31m! #{str}\e[0m"
21
- end
22
-
23
- end
@@ -1,58 +0,0 @@
1
- =begin
2
- Copyright 2016 - Niji
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- =end
16
-
17
- class String
18
-
19
- def delete_objc_prefix
20
- i = 0
21
- while i < self.length - 1 and /[[:upper:]]/.match(self[i+1])
22
- i += 1
23
- end
24
- self[i..self.length]
25
- end
26
-
27
- def delete_inverse_suffix
28
- self.gsub('_', '')
29
- end
30
-
31
- def capitalize_first_letter
32
- self.slice(0, 1).capitalize + self.slice(1..-1)
33
- end
34
-
35
- def camel_case
36
- words = self.scan(/[A-Z][a-z]+/)
37
- words.map!(&:upcase)
38
- words.join('_')
39
- end
40
-
41
- def underscore
42
- self.gsub(/::/, '/').
43
- gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
44
- gsub(/([a-z\d])([A-Z])/, '\1_\2').
45
- tr('-', '_').
46
- downcase
47
- end
48
-
49
- def add_quotes
50
- "\"" + self + "\""
51
- end
52
-
53
- def add_parentheses
54
- '(' + self + ')'
55
- end
56
-
57
-
58
- end
@@ -1,98 +0,0 @@
1
- =begin
2
- Copyright 2016 - Niji
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- =end
16
-
17
- module Gyro
18
- module XCDataModel
19
- module Parser
20
-
21
- class Attribute
22
-
23
- attr_accessor :entity_name, :name, :type, :optional, :indexed, :default
24
- attr_accessor :realm_ignored, :realm_read_only, :enum_type, :enum_values
25
- attr_accessor :json_key_path, :json_values, :transformer, :comment, :support_annotation
26
-
27
- alias_method :optional?, :optional
28
- alias_method :indexed?, :indexed
29
- alias_method :realm_ignored?, :realm_ignored
30
-
31
- def initialize (attribute_xml, entity_name)
32
- @entity_name = entity_name
33
- @name = attribute_xml.xpath('@name').to_s
34
- @optional = attribute_xml.xpath('@optional').to_s == 'YES' ? true : false
35
- @indexed = attribute_xml.xpath('@indexed').to_s == 'YES' ? true : false
36
- @default = attribute_xml.xpath('@defaultValueString').to_s
37
- @type = attribute_xml.xpath('@attributeType').to_s.downcase.gsub(' ', '_').to_sym
38
- @realm_ignored = attribute_xml.xpath(USERINFO_VALUE%['realmIgnored']).to_s.empty? ? false : true
39
- @realm_read_only = attribute_xml.xpath(USERINFO_VALUE%['realmReadOnly']).to_s
40
- @enum_type = attribute_xml.xpath(USERINFO_VALUE%['enumType']).to_s
41
- @enum_values = attribute_xml.xpath(USERINFO_VALUE%['enumValues']).to_s.split(',')
42
- @json_key_path = attribute_xml.xpath(USERINFO_VALUE%['JSONKeyPath']).to_s
43
- @json_values = attribute_xml.xpath(USERINFO_VALUE%['JSONValues']).to_s.split(',')
44
- @transformer = attribute_xml.xpath(USERINFO_VALUE%['transformer']).to_s.strip
45
- @comment = attribute_xml.xpath(USERINFO_VALUE%['comment']).to_s
46
- @support_annotation = attribute_xml.xpath(USERINFO_VALUE%['supportAnnotation']).to_s
47
- search_for_error
48
- end
49
-
50
- def enum?
51
- !@enum_type.empty?
52
- end
53
-
54
- def read_only?
55
- !@realm_read_only.empty?
56
- end
57
-
58
- def has_default?
59
- !@default.empty?
60
- end
61
-
62
- def to_s
63
- "\tAttribute => name=#{@name} | type=#{@type} | optional=#{@optional} | default=#{@default} | indexed=#{@indexed}\n"
64
- end
65
-
66
- def is_decimal?
67
- @type == :decimal or @type == :double or @type == :float
68
- end
69
-
70
- def is_integer?
71
- @type == :integer_16 or @type == :integer_32 or @type == :integer_64
72
- end
73
-
74
- def is_number?
75
- is_decimal? or is_integer?
76
- end
77
-
78
- def is_bool?
79
- @type == :boolean
80
- end
81
-
82
- def need_transformer?
83
- !@enum_type.empty? or @type == :boolean or @type == :date or !@transformer.empty?
84
- end
85
-
86
- private ################################################################
87
-
88
- def search_for_error
89
- Raise::error("The attribute \"%s\" from \"%s\" has no type - please fix it"%[@name, @entity_name]) if @type == :undefined || @type.empty?
90
- Raise::error("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?
91
- Raise::error("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
92
- end
93
-
94
- end
95
-
96
- end
97
- end
98
- end