gyro 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +201 -0
- data/README.md +840 -0
- data/bin/gyro +118 -0
- data/lib/gyro.rb +32 -0
- data/lib/gyro/realm/java/converter.rb +63 -0
- data/lib/gyro/realm/java/enum_generator.rb +128 -0
- data/lib/gyro/realm/java/generator.rb +183 -0
- data/lib/gyro/realm/java/templates.rb +67 -0
- data/lib/gyro/realm/objc/converter.rb +63 -0
- data/lib/gyro/realm/objc/enum_generator.rb +86 -0
- data/lib/gyro/realm/objc/generator.rb +373 -0
- data/lib/gyro/realm/objc/json_category_generator.rb +172 -0
- data/lib/gyro/realm/objc/protocol_generator.rb +59 -0
- data/lib/gyro/realm/objc/templates.rb +100 -0
- data/lib/gyro/realm/swift/converter.rb +74 -0
- data/lib/gyro/realm/swift/enum_generator.rb +73 -0
- data/lib/gyro/realm/swift/generator.rb +265 -0
- data/lib/gyro/realm/swift/object_mapper_generator.rb +124 -0
- data/lib/gyro/realm/swift/templates.rb +64 -0
- data/lib/gyro/utils/file_utils.rb +31 -0
- data/lib/gyro/utils/log.rb +68 -0
- data/lib/gyro/utils/raise.rb +23 -0
- data/lib/gyro/utils/string_xcdatamodel.rb +58 -0
- data/lib/gyro/xcdatamodel/parser/attribute.rb +98 -0
- data/lib/gyro/xcdatamodel/parser/entity.rb +234 -0
- data/lib/gyro/xcdatamodel/parser/relationship.rb +70 -0
- data/lib/gyro/xcdatamodel/parser/xcdatamodel.rb +59 -0
- metadata +77 -0
@@ -0,0 +1,70 @@
|
|
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('../../xcdatamodel/parser/relationship', File.dirname(__FILE__))
|
18
|
+
|
19
|
+
module Gyro
|
20
|
+
module XCDataModel
|
21
|
+
module Parser
|
22
|
+
|
23
|
+
class Relationship
|
24
|
+
|
25
|
+
attr_accessor :entity_name, :name, :type, :optional, :deletion_rule, :inverse_name, :inverse_type, :json_key_path, :support_annotation
|
26
|
+
attr_accessor :realm_ignored
|
27
|
+
attr_accessor :destination
|
28
|
+
|
29
|
+
alias_method :realm_ignored?, :realm_ignored
|
30
|
+
|
31
|
+
def initialize(relationship_xml, entity_name)
|
32
|
+
@entity_name = entity_name
|
33
|
+
@name = relationship_xml.xpath('@name').to_s
|
34
|
+
@optional = relationship_xml.xpath('@optional').to_s
|
35
|
+
@deletion_rule = relationship_xml.xpath('@deletionRule').to_s
|
36
|
+
@inverse_name = relationship_xml.xpath('@inverseName').to_s
|
37
|
+
@inverse_type = relationship_xml.xpath('@destinationEntity').to_s
|
38
|
+
@json_key_path = relationship_xml.xpath(USERINFO_VALUE%['JSONKeyPath']).to_s
|
39
|
+
@realm_ignored = relationship_xml.xpath(USERINFO_VALUE%['realmIgnored']).to_s.empty? ? false : true
|
40
|
+
@support_annotation = relationship_xml.xpath(USERINFO_VALUE%['supportAnnotation']).to_s
|
41
|
+
load_type(relationship_xml)
|
42
|
+
@destination = relationship_xml.xpath(USERINFO_VALUE%['destination']).to_s
|
43
|
+
search_for_error
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_s
|
47
|
+
"\tRelationship => name=#{@name} | type=#{@type} | optional=#{@optional} | deletion_rule=#{@deletion_rule}\n"
|
48
|
+
end
|
49
|
+
|
50
|
+
def inverse?
|
51
|
+
@name.end_with?('_')
|
52
|
+
end
|
53
|
+
|
54
|
+
private ################################################################
|
55
|
+
|
56
|
+
def load_type(relationship_xml)
|
57
|
+
max_count = relationship_xml.xpath('@maxCount').to_s
|
58
|
+
@type = (!max_count.nil? and max_count == '1') ? :to_one : :to_many
|
59
|
+
end
|
60
|
+
|
61
|
+
def search_for_error
|
62
|
+
Raise::error("The relationship \"%s\" from \"%s\" is wrong - please fix it"%[name, entity_name]) if inverse_type.empty? && destination.empty?
|
63
|
+
Raise::error("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
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,59 @@
|
|
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 'nokogiri'
|
18
|
+
require File.expand_path('../../utils/raise', File.dirname(__FILE__))
|
19
|
+
require File.expand_path('entity', File.dirname(__FILE__))
|
20
|
+
|
21
|
+
module Gyro
|
22
|
+
module XCDataModel
|
23
|
+
module Parser
|
24
|
+
USERINFO_VALUE = "userInfo/entry[@key='%s']/@value"
|
25
|
+
|
26
|
+
class XCDataModel
|
27
|
+
|
28
|
+
attr_accessor :entities
|
29
|
+
|
30
|
+
def initialize(xcdatamodel_dir)
|
31
|
+
contents_file = File.join(xcdatamodel_dir, 'contents')
|
32
|
+
Raise::error('Unable to find contents of xcdatamodel dir') unless File.exist?(contents_file)
|
33
|
+
@entities = Hash.new
|
34
|
+
file = File.open(contents_file)
|
35
|
+
document_xml = Nokogiri::XML(file).remove_namespaces!
|
36
|
+
file.close
|
37
|
+
load_entities(document_xml)
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
str = String.new
|
42
|
+
@entities.each do |_, value|
|
43
|
+
str += value.to_s
|
44
|
+
end
|
45
|
+
str
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def load_entities(document_xml)
|
51
|
+
document_xml.xpath('//entity').each do |node|
|
52
|
+
entity = Entity.new(node)
|
53
|
+
@entities[entity.name] = entity
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gyro
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- NijiDigital
|
8
|
+
- Olivier Halligon
|
9
|
+
- François Ganard
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2017-04-10 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: " This tools allows you to use the visual Xcode editor to design your
|
16
|
+
DataModels\n using the xcdatamodel format (originally designed for CoreData)
|
17
|
+
but then \n generate the code for Realm.io models for Swift, Java & ObjC from
|
18
|
+
that xcdatamodel.\n\n This way you can take advantage of the xcdatamodel visual
|
19
|
+
editor and Xcode integration\n while using Realm instead of CoreData.\n"
|
20
|
+
email: contact@niji.fr
|
21
|
+
executables:
|
22
|
+
- gyro
|
23
|
+
extensions: []
|
24
|
+
extra_rdoc_files: []
|
25
|
+
files:
|
26
|
+
- LICENSE
|
27
|
+
- README.md
|
28
|
+
- bin/gyro
|
29
|
+
- lib/gyro.rb
|
30
|
+
- lib/gyro/realm/java/converter.rb
|
31
|
+
- lib/gyro/realm/java/enum_generator.rb
|
32
|
+
- lib/gyro/realm/java/generator.rb
|
33
|
+
- lib/gyro/realm/java/templates.rb
|
34
|
+
- lib/gyro/realm/objc/converter.rb
|
35
|
+
- lib/gyro/realm/objc/enum_generator.rb
|
36
|
+
- lib/gyro/realm/objc/generator.rb
|
37
|
+
- lib/gyro/realm/objc/json_category_generator.rb
|
38
|
+
- lib/gyro/realm/objc/protocol_generator.rb
|
39
|
+
- lib/gyro/realm/objc/templates.rb
|
40
|
+
- lib/gyro/realm/swift/converter.rb
|
41
|
+
- lib/gyro/realm/swift/enum_generator.rb
|
42
|
+
- lib/gyro/realm/swift/generator.rb
|
43
|
+
- lib/gyro/realm/swift/object_mapper_generator.rb
|
44
|
+
- lib/gyro/realm/swift/templates.rb
|
45
|
+
- lib/gyro/utils/file_utils.rb
|
46
|
+
- lib/gyro/utils/log.rb
|
47
|
+
- lib/gyro/utils/raise.rb
|
48
|
+
- lib/gyro/utils/string_xcdatamodel.rb
|
49
|
+
- lib/gyro/xcdatamodel/parser/attribute.rb
|
50
|
+
- lib/gyro/xcdatamodel/parser/entity.rb
|
51
|
+
- lib/gyro/xcdatamodel/parser/relationship.rb
|
52
|
+
- lib/gyro/xcdatamodel/parser/xcdatamodel.rb
|
53
|
+
homepage: http://rubygems.org/gems/gyro
|
54
|
+
licenses:
|
55
|
+
- Apache-2.0
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.0.0
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.6.7
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Generate Realm.io models for Swift, Java & ObjC from xcdatamodel
|
77
|
+
test_files: []
|