cdqi 7.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3bc412c0020cbe1a735bd898bd076912d77aaa14
4
+ data.tar.gz: '0191c1d8509f34d9a8f7984f5cfb12ab24aba57d'
5
+ SHA512:
6
+ metadata.gz: 5912f8e054ae88475ad040a8ee5a63203bdf9baf8edae7e900acab2958b1240418702c0f0d2117048a66d8d9d93a2349784800311e106d38f97252baaa1ae435
7
+ data.tar.gz: 24b4dce573954653a60c926410b9156615851e70d18370543e619eea938b22eb4f14212f7af39949ba5a242d9c3a61d9a5a02503af604f5a1976fa880dc3c4d6
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in cdqi.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Gregory Higley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Cdqi
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cdqi`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cdqi'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cdqi
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cdqi.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cdqi"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/cdqi.gemspec ADDED
@@ -0,0 +1,26 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cdqi/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cdqi"
8
+ spec.version = CDQI::VERSION
9
+ spec.authors = ["Gregory Higley"]
10
+ spec.email = ["code@revolucent.net"]
11
+
12
+ spec.summary = %q{Creates proxy objects for Core Data Query Interface.}
13
+ spec.description = %q{Creates proxy objects for Core Data Query Interface.}
14
+ spec.homepage = "https://github.com/prosumma/cdqi"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = ["cdqi"]
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
data/exe/cdqi ADDED
@@ -0,0 +1,263 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cdqi'
4
+
5
+ require 'date'
6
+ require 'find'
7
+ require 'optparse'
8
+ require 'ostruct'
9
+
10
+ RESERVED_ATTRIBUTE_NAMES = %w{count sum average max min}
11
+
12
+ $options = OpenStruct::new
13
+ $options.force = false
14
+ $options.input_path = "."
15
+ $options.output_path = nil
16
+ $options.merged = false
17
+ $options.excluded_entities = []
18
+ $options.included_entities = []
19
+ $options.access_modifier = ""
20
+ $options.suffix = "Attribute"
21
+ $options.indent = 4
22
+
23
+ option_parser = OptionParser::new do |opts|
24
+ opts.on("-f", "--force", "Force overwrite existing files") do |opt|
25
+ $options.force = opt
26
+ end
27
+ opts.on("-i", "--in=PATH", "Where to start searching for the data model (defaults to current directory)") do |opt|
28
+ $options.input_path = File::expand_path(opt)
29
+ end
30
+ opts.on("-o", "--out=PATH", "Where to put the resulting files (defaults to same directory as data model)") do |opt|
31
+ $options.output_path = File::expand_path(opt)
32
+ end
33
+ opts.on("-m", "--merged", "Creates a single file using the name of the data model") do |opt|
34
+ $options.merged = opt
35
+ end
36
+ opts.on("-x", "--exclude=ENTITY", "Exclude an entity") do |opt|
37
+ $options.excluded_entities << opt
38
+ end
39
+ opts.on("-w", "--write=ENTITY", "Write only this entity to the output") do |opt|
40
+ $options.included_entities << opt
41
+ end
42
+ opts.on("-a", "--access=ACCESS", [:public, :private, :internal], "Set access modifier of generated classes (defaults to public)") do |opt|
43
+ $options.access_modifier = "#{opt || 'public'} "
44
+ end
45
+ opts.on("-s", "--suffix=SUFFIX", "Suffix to use on generated classes and filenames (defaults to Attribute)") do |opt|
46
+ $options.suffix = opt
47
+ end
48
+ opts.on("-n", "--indent=COUNT", OptionParser::DecimalInteger, "Number of spaces to indent (defaults to 2)") do |opt|
49
+ $options.indent = opt
50
+ end
51
+ end
52
+
53
+ models = option_parser.parse(ARGV)
54
+ if models.length == 0
55
+ abort "ERROR: No data model specified. Quitting."
56
+ elsif models.length > 1
57
+ abort "ERROR: Multiple data models specified. Please specify only one data model. Quitting."
58
+ end
59
+
60
+ model = models[0]
61
+ model_path = nil
62
+
63
+ Find::find($options.input_path) do |path|
64
+ if path =~ /#{Regexp.quote(model)}\.xcdatamodeld$/
65
+ model_path = path
66
+ $options.output_path ||= File::dirname(path)
67
+ break
68
+ end
69
+ end
70
+
71
+ abort "Could not find #{model} data model in #{$options.input_path}. Quitting." if model_path.nil?
72
+
73
+ require 'rexml/document'
74
+ require 'rexml/xpath'
75
+
76
+ class IndentWriter
77
+ def initialize(io)
78
+ @io = io
79
+ @level = 0
80
+ end
81
+ def puts(s)
82
+ @io.puts "#{''.ljust($options.indent * @level, ' ')}#{s}"
83
+ end
84
+ def indent(level = 1)
85
+ @level += level
86
+ yield
87
+ @level -= level
88
+ end
89
+ end
90
+
91
+ class Attribute
92
+ def initialize(name, entity: nil, type: nil)
93
+ @name = name
94
+ @entity = entity
95
+ @type = type
96
+ end
97
+
98
+ def attribute_class_name
99
+ prefix = ''
100
+ if @type
101
+ case @type
102
+ when 'Binary' then 'DataAttribute'
103
+ when 'Boolean' then 'BoolAttribute'
104
+ when 'Date' then 'DateAttribute'
105
+ when 'Decimal' then 'DecimalAttribute'
106
+ when 'Double' then 'DoubleAttribute'
107
+ when 'Float' then 'FloatAttribute'
108
+ when 'Integer 16' then 'Int16Attribute'
109
+ when 'Integer 32' then 'Int32Attribute'
110
+ when 'Integer 64' then 'Int64Attribute'
111
+ when 'String' then 'StringAttribute'
112
+ else
113
+ raise @type
114
+ end
115
+ else
116
+ "#{@entity}#{$options.suffix}"
117
+ end
118
+ end
119
+
120
+ def render(io)
121
+ io.puts "#{$options.access_modifier}private(set) lazy var #{@name}: #{attribute_class_name} = { #{attribute_class_name}(key: \"#{@name}\", parent: self) }()"
122
+ end
123
+ end
124
+
125
+ class Entity
126
+ attr_reader :name, :entity_class_name
127
+ def initialize(name)
128
+ @name = name
129
+ @attributes = []
130
+ @entity_class_name = "#{@name}#{$options.suffix}"
131
+ end
132
+ def <<(attribute)
133
+ @attributes << attribute
134
+ end
135
+ def render(io)
136
+ io.puts "#{$options.access_modifier}final class #{@entity_class_name}: EntityAttribute, Subqueryable {"
137
+ io.indent do
138
+ @attributes.each do |attribute|
139
+ attribute.render(io)
140
+ end
141
+ end
142
+ io.puts "}"
143
+ io.puts ""
144
+ io.puts "extension #{@name}: Entity {"
145
+ io.indent do
146
+ io.puts "#{$options.access_modifier}typealias CDQIEntityAttribute = #{@entity_class_name}"
147
+ end
148
+ io.puts "}"
149
+ io.puts ""
150
+ end
151
+ end
152
+
153
+ entities = []
154
+
155
+ currentversion_path = File::join(model_path, '.xccurrentversion')
156
+ if File::exists? currentversion_path
157
+ File::open(currentversion_path) do |fd|
158
+ xml = REXML::Document::new(fd)
159
+ model_path = File::join(model_path, REXML::XPath::first(xml, "//key[.='_XCCurrentVersionName']/following-sibling::string").text)
160
+ $stderr.puts "NOTICE: Using data model at #{model_path}."
161
+ model_path = File::join(model_path, 'contents')
162
+ end
163
+ else
164
+ model_path = File::join(model_path, "#{model}.xcdatamodel/contents")
165
+ end
166
+
167
+ File::open(model_path) do |fd|
168
+ xml = REXML::Document::new(fd)
169
+ classes_by_entity_name = {}
170
+ # Build map of entity_name => class and excluded entities
171
+ xml.root.elements.each('entity') do |entity_node|
172
+ entity_name = entity_node.attributes['name']
173
+ represented_class = entity_node.attributes['representedClassName']
174
+ excluded = false
175
+ if represented_class.nil?
176
+ $stderr.puts "WARNING: The entity '#{entity_name}' was skipped because it has no represented class."
177
+ excluded = true
178
+ else
179
+ represented_class = represented_class.split('.')[-1]
180
+ end
181
+ if ['String', 'Numeric', 'Date', 'Data', 'Entity'].include?(represented_class) && $options.suffix == 'Attribute'
182
+ $stderr.puts "WARNING: The entity '#{entity_name}' represented by the class '#{represented_class}' was skipped because the name of its generated proxy would conflict with CDQI's '#{represented_class}Attribute'. You can avoid this by using a different represented class name or a suffix other than 'Attribute'."
183
+ excluded = true
184
+ end
185
+ if excluded
186
+ $options.excluded_entities << entity_name
187
+ next
188
+ else
189
+ classes_by_entity_name[entity_name] = represented_class
190
+ end
191
+ end
192
+ xml.root.elements.each('entity') do |entity_node|
193
+ entity_name = entity_node.attributes['name']
194
+ represented_class = classes_by_entity_name[entity_name]
195
+ if !$options.excluded_entities.include?(entity_name) && ($options.included_entities.empty? || $options.included_entities.include?(entity_name))
196
+ entity_name = represented_class.split('.')[-1]
197
+ entity = Entity::new(entity_name)
198
+ entity_node.elements.each('attribute') do |attribute_node|
199
+ attribute_name = attribute_node.attributes['name']
200
+ if RESERVED_ATTRIBUTE_NAMES.include?(attribute_name)
201
+ $stderr.puts "WARNING: The attribute '#{attribute_name}' in the '#{entity_node.attributes['name']}' entity has been skipped because it conflicts with the name of an aggregate property."
202
+ else
203
+ attribute_type = attribute_node.attributes['attributeType']
204
+ if attribute_type == 'Transformable' then
205
+ $stderr.puts "WARNING: The attribute '#{attribute_name}' in the '#{entity_node.attributes['name']}' entity has been skipped because it is a transformable attribute. Transformable attributes are not currently supported."
206
+ else
207
+ entity << Attribute::new(attribute_name, entity: nil, type: attribute_type)
208
+ end
209
+ end
210
+ end
211
+ entity_node.elements.each('relationship') do |relationship_node|
212
+ destination_entity_name = relationship_node.attributes['destinationEntity']
213
+ destination_class = classes_by_entity_name[destination_entity_name]
214
+ unless $options.excluded_entities.include?(destination_entity_name) || destination_class.nil?
215
+ attribute_name = relationship_node.attributes['name']
216
+ entity << Attribute::new(attribute_name, entity: destination_class)
217
+ end
218
+ end
219
+ entities << entity
220
+ end
221
+ end
222
+ end
223
+
224
+ def write_file_header(io)
225
+ io.puts "//"
226
+ io.puts "// Generated by CDQI on #{DateTime::now.strftime('%Y-%m-%d')}."
227
+ io.puts "//"
228
+ io.puts "// This file was generated by a tool. Further invocations of this tool will overwrite this file."
229
+ io.puts "// Edit it at your own risk."
230
+ io.puts "//"
231
+ io.puts ""
232
+ io.puts "import CoreDataQueryInterface"
233
+ io.puts ""
234
+ end
235
+
236
+ if $options.merged
237
+ output_file = File.join($options.output_path, "#{model}#{$options.suffix}.swift")
238
+ if $options.force || !File.exists?(output_file)
239
+ File::open(output_file, 'w') do |io|
240
+ write_file_header io
241
+ iw = IndentWriter::new(io)
242
+ entities.each do |entity|
243
+ entity.render iw
244
+ end
245
+ end
246
+ $stderr.puts "NOTICE: Wrote file #{output_file}."
247
+ else
248
+ abort "ERROR: The file '#{output_file}' exists and --force was not specified. Quitting."
249
+ end
250
+ else
251
+ entities.each do |entity|
252
+ output_file = File.join($options.output_path, "#{entity.name}#{$options.suffix}.swift")
253
+ if $options.force || !File.exists?(output_file)
254
+ File::open(output_file, 'w') do |io|
255
+ write_file_header io
256
+ entity.render IndentWriter::new(io)
257
+ end
258
+ $stderr.puts "NOTICE: Wrote file #{output_file}."
259
+ else
260
+ $stderr.puts "WARNING: The file '#{output_file}' exists and --force was not specified. Skipping."
261
+ end
262
+ end
263
+ end
@@ -0,0 +1,3 @@
1
+ module CDQI
2
+ VERSION = "7.0.0"
3
+ end
data/lib/cdqi.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "cdqi/version"
2
+
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cdqi
3
+ version: !ruby/object:Gem::Version
4
+ version: 7.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gregory Higley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Creates proxy objects for Core Data Query Interface.
42
+ email:
43
+ - code@revolucent.net
44
+ executables:
45
+ - cdqi
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".ruby-version"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - cdqi.gemspec
58
+ - exe/cdqi
59
+ - lib/cdqi.rb
60
+ - lib/cdqi/version.rb
61
+ homepage: https://github.com/prosumma/cdqi
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.6.13
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Creates proxy objects for Core Data Query Interface.
85
+ test_files: []