core_data 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/Gemfile.lock +8 -5
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +4 -6
- data/Rakefile +7 -5
- data/core_data.gemspec +16 -15
- data/lib/core_data.rb +2 -0
- data/lib/core_data/data_model.rb +6 -4
- data/lib/core_data/data_model/attribute.rb +29 -23
- data/lib/core_data/data_model/entity.rb +4 -2
- data/lib/core_data/data_model/relationship.rb +8 -6
- data/lib/core_data/version.rb +3 -1
- metadata +21 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd8ceef611144a6fd8a9565b4d9105c15d9a76c1
|
4
|
+
data.tar.gz: ccfe3e1f93cb8218b7b008fd1b732d1eda6bf486
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d82117e89ce6bfadf09ffb499a806388cf71ececb2a9a73c756519b6a832d2cfd8d2f5d23c26b0d4fb7a47fd4b07ee8f3e6af3ea13ff0f4d3831e337c1613d4f
|
7
|
+
data.tar.gz: 1b61deb7fe20050c06aef462f5942ab2349b201ea84139279145f0340282199776851e6b767306566e459f22a36a388658783395d0a6d66b4f27df401d1369ec
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
core_data (0.
|
4
|
+
core_data (0.2.0)
|
5
5
|
nokogiri (~> 1.4)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
nokogiri (1.
|
12
|
-
|
13
|
-
rake (
|
10
|
+
mini_portile2 (2.4.0)
|
11
|
+
nokogiri (1.10.3)
|
12
|
+
mini_portile2 (~> 2.4.0)
|
13
|
+
rake (12.3.2)
|
14
14
|
|
15
15
|
PLATFORMS
|
16
16
|
ruby
|
@@ -18,3 +18,6 @@ PLATFORMS
|
|
18
18
|
DEPENDENCIES
|
19
19
|
core_data!
|
20
20
|
rake
|
21
|
+
|
22
|
+
BUNDLED WITH
|
23
|
+
2.0.1
|
data/{LICENSE → LICENSE.md}
RENAMED
data/README.md
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# Core Data
|
2
|
+
|
2
3
|
**Parse Core Data Model (.xcdatamodel) Files**
|
3
4
|
|
4
5
|
## Contact
|
5
6
|
|
6
|
-
Mattt
|
7
|
-
|
8
|
-
- http://github.com/mattt
|
9
|
-
- http://twitter.com/mattt
|
10
|
-
- m@mattt.me
|
7
|
+
[Mattt](https://twitter.com/mattt)
|
11
8
|
|
12
9
|
## License
|
13
10
|
|
14
|
-
Core Data is released under an MIT license.
|
11
|
+
Core Data is released under an MIT license.
|
12
|
+
See LICENSE for more information.
|
data/Rakefile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler'
|
2
4
|
Bundler.setup
|
3
5
|
|
4
|
-
gemspec = eval(File.read(
|
6
|
+
gemspec = eval(File.read('core_data.gemspec'))
|
5
7
|
|
6
|
-
task :
|
8
|
+
task build: "#{gemspec.full_name}.gem"
|
7
9
|
|
8
|
-
file "#{gemspec.full_name}.gem" => gemspec.files + [
|
9
|
-
system
|
10
|
+
file "#{gemspec.full_name}.gem" => gemspec.files + ['core_data.gemspec'] do
|
11
|
+
system 'gem build core_data.gemspec'
|
10
12
|
end
|
data/core_data.gemspec
CHANGED
@@ -1,24 +1,25 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
require 'core_data/version'
|
4
5
|
|
5
6
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
7
|
-
s.authors = [
|
8
|
-
s.email =
|
9
|
-
s.homepage =
|
10
|
-
s.license =
|
7
|
+
s.name = 'core_data'
|
8
|
+
s.authors = ['Mattt Thompson']
|
9
|
+
s.email = 'm@mattt.me'
|
10
|
+
s.homepage = 'http://mattt.me'
|
11
|
+
s.license = 'MIT'
|
11
12
|
s.version = CoreData::VERSION
|
12
13
|
s.platform = Gem::Platform::RUBY
|
13
|
-
s.summary =
|
14
|
-
s.description =
|
14
|
+
s.summary = 'Core Data'
|
15
|
+
s.description = 'Parse Core Data models.'
|
15
16
|
|
16
|
-
s.add_development_dependency
|
17
|
+
s.add_development_dependency 'rake'
|
17
18
|
|
18
|
-
s.add_dependency
|
19
|
+
s.add_dependency 'nokogiri', '~> 1.4'
|
19
20
|
|
20
|
-
s.files = Dir[
|
21
|
+
s.files = Dir['./**/*'].reject { |file| file =~ %r{\./(bin|example|log|pkg|script|spec|test|vendor)} }
|
21
22
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
-
s.require_paths = [
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
24
|
+
s.require_paths = ['lib']
|
24
25
|
end
|
data/lib/core_data.rb
CHANGED
data/lib/core_data/data_model.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'nokogiri'
|
2
4
|
|
3
5
|
module CoreData
|
@@ -8,13 +10,13 @@ module CoreData
|
|
8
10
|
loop do
|
9
11
|
case data_model
|
10
12
|
when File, /^\<\?xml/
|
11
|
-
data_model = ::Nokogiri::XML(data_model)
|
13
|
+
(data_model = ::Nokogiri::XML(data_model)) && redo
|
12
14
|
when String
|
13
15
|
case data_model
|
14
16
|
when /\.xcdatamodeld?$/
|
15
|
-
data_model = Dir[File.join(data_model,
|
17
|
+
(data_model = Dir[File.join(data_model, '/**/contents')].first) && redo
|
16
18
|
else
|
17
|
-
data_model = ::File.read(data_model)
|
19
|
+
(data_model = ::File.read(data_model)) && redo
|
18
20
|
end
|
19
21
|
when ::Nokogiri::XML::Document
|
20
22
|
break
|
@@ -27,7 +29,7 @@ module CoreData
|
|
27
29
|
|
28
30
|
@name = model['name']
|
29
31
|
@version = model['systemVersion']
|
30
|
-
@entities = model.xpath('entity').collect{|element| Entity.new(element)}
|
32
|
+
@entities = model.xpath('entity').collect { |element| Entity.new(element) }
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CoreData
|
2
4
|
class DataModel
|
3
5
|
class Attribute
|
@@ -15,20 +17,24 @@ module CoreData
|
|
15
17
|
@minimum_value = range_value_from_string(attribute['minValueString'])
|
16
18
|
@maximum_value = range_value_from_string(attribute['maxValueString'])
|
17
19
|
|
18
|
-
@regular_expression =
|
20
|
+
@regular_expression = begin
|
21
|
+
Regexp.new(attributes['regularExpressionString'])
|
22
|
+
rescue StandardError
|
23
|
+
nil
|
24
|
+
end
|
19
25
|
|
20
|
-
@optional = attribute['optional'] ==
|
21
|
-
@transient = attribute['transient'] ==
|
22
|
-
@indexed = attribute['indexed'] ==
|
23
|
-
@syncable = attribute['syncable'] ==
|
26
|
+
@optional = attribute['optional'] == 'YES'
|
27
|
+
@transient = attribute['transient'] == 'YES'
|
28
|
+
@indexed = attribute['indexed'] == 'YES'
|
29
|
+
@syncable = attribute['syncable'] == 'YES'
|
24
30
|
end
|
25
31
|
|
26
32
|
def to_s
|
27
33
|
[@name, @type].to_s
|
28
34
|
end
|
29
35
|
|
30
|
-
[
|
31
|
-
define_method("#{symbol}?") {!!instance_variable_get(
|
36
|
+
%i[optional transient indexed syncable].each do |symbol|
|
37
|
+
define_method("#{symbol}?") { !!instance_variable_get("@#{symbol}".intern) }
|
32
38
|
end
|
33
39
|
|
34
40
|
private
|
@@ -36,28 +42,28 @@ module CoreData
|
|
36
42
|
def default_value_from_string(string)
|
37
43
|
return nil unless string
|
38
44
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
case @type
|
46
|
+
when 'Integer 16', 'Integer 32', 'Integer 64'
|
47
|
+
string.to_i
|
48
|
+
when 'Float', 'Decimal'
|
49
|
+
string.to_f
|
50
|
+
when 'Boolean'
|
51
|
+
string == 'YES'
|
52
|
+
else
|
53
|
+
string
|
48
54
|
end
|
49
55
|
end
|
50
56
|
|
51
57
|
def range_value_from_string(string)
|
52
58
|
return nil unless string
|
53
59
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
60
|
+
case @type
|
61
|
+
when 'Float', 'Decimal'
|
62
|
+
string.to_f
|
63
|
+
when 'Date'
|
64
|
+
string
|
65
|
+
else
|
66
|
+
string.to_i
|
61
67
|
end
|
62
68
|
end
|
63
69
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CoreData
|
2
4
|
class DataModel
|
3
5
|
class Entity
|
@@ -7,8 +9,8 @@ module CoreData
|
|
7
9
|
raise ArgumentError unless ::Nokogiri::XML::Element === entity
|
8
10
|
|
9
11
|
@name = entity['name']
|
10
|
-
@attributes = entity.xpath('attribute').collect{|element| Attribute.new(element)}
|
11
|
-
@relationships = entity.xpath('relationship').collect{|element| Relationship.new(element)}
|
12
|
+
@attributes = entity.xpath('attribute').collect { |element| Attribute.new(element) }
|
13
|
+
@relationships = entity.xpath('relationship').collect { |element| Relationship.new(element) }
|
12
14
|
end
|
13
15
|
|
14
16
|
def to_s
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CoreData
|
2
4
|
class DataModel
|
3
5
|
class Relationship
|
@@ -14,10 +16,10 @@ module CoreData
|
|
14
16
|
@min_count = relationship['minCount'].to_i
|
15
17
|
@max_count = relationship['maxCount'].to_i
|
16
18
|
|
17
|
-
@to_many = relationship['toMany'] ==
|
18
|
-
@optional = relationship['optional'] ==
|
19
|
-
@syncable = relationship['syncable'] ==
|
20
|
-
@ordered = relationship['ordered'] ==
|
19
|
+
@to_many = relationship['toMany'] == 'YES'
|
20
|
+
@optional = relationship['optional'] == 'YES'
|
21
|
+
@syncable = relationship['syncable'] == 'YES'
|
22
|
+
@ordered = relationship['ordered'] == 'YES'
|
21
23
|
end
|
22
24
|
|
23
25
|
def to_s
|
@@ -36,8 +38,8 @@ module CoreData
|
|
36
38
|
@ordered
|
37
39
|
end
|
38
40
|
|
39
|
-
[
|
40
|
-
define_method("#{symbol}?") {!!instance_variable_get(
|
41
|
+
%i[optional syncable].each do |symbol|
|
42
|
+
define_method("#{symbol}?") { !!instance_variable_get("@#{symbol}".intern) }
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
data/lib/core_data/version.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: core_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattt Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.4'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.4'
|
41
41
|
description: Parse Core Data models.
|
@@ -44,18 +44,18 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
-
- ./
|
48
|
-
- ./Gemfile
|
49
|
-
- ./
|
50
|
-
- ./
|
51
|
-
- ./
|
52
|
-
- ./
|
53
|
-
- ./lib/core_data
|
54
|
-
- ./lib/core_data/
|
55
|
-
- ./lib/core_data.rb
|
56
|
-
- ./
|
57
|
-
- ./
|
58
|
-
- ./
|
47
|
+
- "./Gemfile"
|
48
|
+
- "./Gemfile.lock"
|
49
|
+
- "./LICENSE.md"
|
50
|
+
- "./README.md"
|
51
|
+
- "./Rakefile"
|
52
|
+
- "./core_data.gemspec"
|
53
|
+
- "./lib/core_data.rb"
|
54
|
+
- "./lib/core_data/data_model.rb"
|
55
|
+
- "./lib/core_data/data_model/attribute.rb"
|
56
|
+
- "./lib/core_data/data_model/entity.rb"
|
57
|
+
- "./lib/core_data/data_model/relationship.rb"
|
58
|
+
- "./lib/core_data/version.rb"
|
59
59
|
homepage: http://mattt.me
|
60
60
|
licenses:
|
61
61
|
- MIT
|
@@ -66,17 +66,17 @@ require_paths:
|
|
66
66
|
- lib
|
67
67
|
required_ruby_version: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
|
-
- -
|
69
|
+
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
78
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.
|
79
|
+
rubygems_version: 2.6.14
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: Core Data
|