core_data 0.0.4 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +5 -7
- data/LICENSE +1 -1
- data/README.md +3 -18
- data/core_data.gemspec +5 -5
- data/lib/core_data.rb +1 -9
- data/lib/core_data/data_model.rb +18 -6
- data/lib/core_data/data_model/attribute.rb +65 -0
- data/lib/core_data/data_model/entity.rb +19 -0
- data/lib/core_data/data_model/relationship.rb +39 -0
- data/lib/core_data/version.rb +3 -0
- metadata +25 -39
- data/core_data-0.0.1.gem +0 -0
- data/core_data-0.0.2.gem +0 -0
- data/core_data-0.0.3.gem +0 -0
- data/lib/core_data/attribute.rb +0 -33
- data/lib/core_data/entity.rb +0 -17
- data/lib/core_data/relationship.rb +0 -37
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a5108b6cd6a33bce264e87722ee40901fdcf51db
|
4
|
+
data.tar.gz: 03cc10252d81bb7aa39a6f64f2811e11c8be2267
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a184a1329ac31e17ca5340b720856fa37d59c5c80bb7c846a0b1063958e9b3c59e066fcc508fe5daff93d18cd1cb9c136388ffb4e9782e51c3d5a12fe159c415
|
7
|
+
data.tar.gz: 7a53564d3d064758833b63197e074ed9676137df58c7951c5bde93f42fcb00b8985c0baba689e449deb949b22b4f374a399bce494ad16da3afee29be94f7b5cf
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
core_data (0.
|
4
|
+
core_data (0.1.1)
|
5
5
|
nokogiri (~> 1.4)
|
6
6
|
|
7
7
|
GEM
|
8
|
-
remote:
|
8
|
+
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
nokogiri (1.5.
|
11
|
-
rake (0.
|
12
|
-
rspec (0.6.4)
|
10
|
+
nokogiri (1.5.9)
|
11
|
+
rake (10.0.4)
|
13
12
|
|
14
13
|
PLATFORMS
|
15
14
|
ruby
|
16
15
|
|
17
16
|
DEPENDENCIES
|
18
17
|
core_data!
|
19
|
-
rake
|
20
|
-
rspec (~> 0.6.1)
|
18
|
+
rake
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,20 +1,5 @@
|
|
1
|
-
#
|
2
|
-
**
|
3
|
-
|
4
|
-
## Installation
|
5
|
-
|
6
|
-
```sh
|
7
|
-
$ gem install core_data
|
8
|
-
```
|
9
|
-
|
10
|
-
## Usage
|
11
|
-
|
12
|
-
```ruby
|
13
|
-
model = CoreData::DataModel.new("/path/to/xml") # or XML string
|
14
|
-
model.entities.each do |entity|
|
15
|
-
p entity, entity.attributes, entity.relationships
|
16
|
-
end
|
17
|
-
```
|
1
|
+
# Core Data
|
2
|
+
**Parse Core Data Model (.xcdatamodel) Files**
|
18
3
|
|
19
4
|
## Contact
|
20
5
|
|
@@ -26,4 +11,4 @@ Mattt Thompson
|
|
26
11
|
|
27
12
|
## License
|
28
13
|
|
29
|
-
|
14
|
+
Core Data is available under the MIT license. See the LICENSE file for more info.
|
data/core_data.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "core_data"
|
3
|
+
require "core_data/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "core_data"
|
7
7
|
s.authors = ["Mattt Thompson"]
|
8
8
|
s.email = "m@mattt.me"
|
9
9
|
s.homepage = "http://mattt.me"
|
10
|
+
s.license = "MIT"
|
10
11
|
s.version = CoreData::VERSION
|
11
12
|
s.platform = Gem::Platform::RUBY
|
12
13
|
s.summary = "Core Data"
|
13
|
-
s.description = "
|
14
|
+
s.description = "Parse Core Data models."
|
14
15
|
|
15
|
-
s.add_development_dependency "
|
16
|
-
s.add_development_dependency "rake", "~> 0.9.2"
|
16
|
+
s.add_development_dependency "rake"
|
17
17
|
|
18
18
|
s.add_dependency "nokogiri", "~> 1.4"
|
19
19
|
|
20
|
-
s.files = Dir["./**/*"].reject { |file| file =~ /\.\/(bin|log|pkg|script|spec|test|vendor)/ }
|
20
|
+
s.files = Dir["./**/*"].reject { |file| file =~ /\.\/(bin|example|log|pkg|script|spec|test|vendor)/ }
|
21
21
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
22
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
23
|
s.require_paths = ["lib"]
|
data/lib/core_data.rb
CHANGED
data/lib/core_data/data_model.rb
CHANGED
@@ -1,14 +1,21 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
1
3
|
module CoreData
|
2
4
|
class DataModel
|
3
5
|
attr_reader :name, :version, :entities
|
4
6
|
|
5
|
-
def initialize(
|
7
|
+
def initialize(data_model)
|
6
8
|
loop do
|
7
|
-
case
|
9
|
+
case data_model
|
8
10
|
when File, /^\<\?xml/
|
9
|
-
|
11
|
+
data_model = ::Nokogiri::XML(data_model) and redo
|
10
12
|
when String
|
11
|
-
|
13
|
+
case data_model
|
14
|
+
when /\.xcdatamodeld?$/
|
15
|
+
data_model = Dir[File.join(data_model, "/**/contents")].first and redo
|
16
|
+
else
|
17
|
+
data_model = ::File.read(data_model) and redo
|
18
|
+
end
|
12
19
|
when ::Nokogiri::XML::Document
|
13
20
|
break
|
14
21
|
else
|
@@ -16,10 +23,15 @@ module CoreData
|
|
16
23
|
end
|
17
24
|
end
|
18
25
|
|
19
|
-
model =
|
26
|
+
model = data_model.at_xpath('model')
|
27
|
+
|
20
28
|
@name = model['name']
|
21
29
|
@version = model['systemVersion']
|
22
30
|
@entities = model.xpath('entity').collect{|element| Entity.new(element)}
|
23
31
|
end
|
24
32
|
end
|
25
|
-
end
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'core_data/data_model/entity'
|
36
|
+
require 'core_data/data_model/attribute'
|
37
|
+
require 'core_data/data_model/relationship'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module CoreData
|
2
|
+
class DataModel
|
3
|
+
class Attribute
|
4
|
+
attr_reader :name, :type, :identifier, :version_hash_modifier, :default_value, :minimum_value, :maximum_value, :regular_expression
|
5
|
+
|
6
|
+
def initialize(attribute)
|
7
|
+
raise ArgumentError unless ::Nokogiri::XML::Element === attribute
|
8
|
+
|
9
|
+
@name = attribute['name']
|
10
|
+
@type = attribute['attributeType']
|
11
|
+
@identifier = attribute['elementID']
|
12
|
+
@version_hash_modifier = attribute['versionHashModifier']
|
13
|
+
|
14
|
+
@default_value = default_value_from_string(attribute['defaultValueString'])
|
15
|
+
@minimum_value = range_value_from_string(attribute['minValueString'])
|
16
|
+
@maximum_value = range_value_from_string(attribute['maxValueString'])
|
17
|
+
|
18
|
+
@regular_expression = Regexp.new(attributes['regularExpressionString']) rescue nil
|
19
|
+
|
20
|
+
@optional = attribute['optional'] == "YES"
|
21
|
+
@transient = attribute['transient'] == "YES"
|
22
|
+
@indexed = attribute['indexed'] == "YES"
|
23
|
+
@syncable = attribute['syncable'] == "YES"
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
[@name, @type].to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
[:optional, :transient, :indexed, :syncable].each do |symbol|
|
31
|
+
define_method("#{symbol}?") {!!instance_variable_get(("@#{symbol}").intern)}
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def default_value_from_string(string)
|
37
|
+
return nil unless string
|
38
|
+
|
39
|
+
return case @type
|
40
|
+
when "Integer 16", "Integer 32", "Integer 64"
|
41
|
+
string.to_i
|
42
|
+
when "Float", "Decimal"
|
43
|
+
string.to_f
|
44
|
+
when "Boolean"
|
45
|
+
string == "YES"
|
46
|
+
else
|
47
|
+
string
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def range_value_from_string(string)
|
52
|
+
return nil unless string
|
53
|
+
|
54
|
+
return case @type
|
55
|
+
when "Float", "Decimal"
|
56
|
+
string.to_f
|
57
|
+
when "Date"
|
58
|
+
string
|
59
|
+
else
|
60
|
+
string.to_i
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module CoreData
|
2
|
+
class DataModel
|
3
|
+
class Entity
|
4
|
+
attr_reader :name, :attributes, :relationships
|
5
|
+
|
6
|
+
def initialize(entity)
|
7
|
+
raise ArgumentError unless ::Nokogiri::XML::Element === entity
|
8
|
+
|
9
|
+
@name = entity['name']
|
10
|
+
@attributes = entity.xpath('attribute').collect{|element| Attribute.new(element)}
|
11
|
+
@relationships = entity.xpath('relationship').collect{|element| Relationship.new(element)}
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
@name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module CoreData
|
2
|
+
class DataModel
|
3
|
+
class Relationship
|
4
|
+
attr_reader :name, :destination, :inverse, :deletion_rule, :min_count, :max_count
|
5
|
+
|
6
|
+
def initialize(relationship)
|
7
|
+
raise ArgumentError unless ::Nokogiri::XML::Element === relationship
|
8
|
+
|
9
|
+
@name = relationship['name']
|
10
|
+
@destination = relationship['destinationEntity']
|
11
|
+
@inverse = relationship['inverseName']
|
12
|
+
@deletion_rule = relationship['deletionRule'].downcase.to_sym
|
13
|
+
|
14
|
+
@min_count = relationship['minCount'].to_i
|
15
|
+
@max_count = relationship['maxCount'].to_i
|
16
|
+
|
17
|
+
@to_many = relationship['toMany'] == "YES"
|
18
|
+
@optional = relationship['optional'] == "YES"
|
19
|
+
@syncable = relationship['syncable'] == "YES"
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
@name
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_many?
|
27
|
+
!!@to_many
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_one?
|
31
|
+
!to_many?
|
32
|
+
end
|
33
|
+
|
34
|
+
[:optional, :syncable].each do |symbol|
|
35
|
+
define_method("#{symbol}?") {!!instance_variable_get(("@#{symbol}").intern)}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,97 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: core_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mattt Thompson
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
17
|
-
none: false
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0
|
19
|
+
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: rake
|
27
|
-
requirement: &70145917108180 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
23
|
requirements:
|
30
|
-
- -
|
24
|
+
- - ! '>='
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *70145917108180
|
26
|
+
version: '0'
|
36
27
|
- !ruby/object:Gem::Dependency
|
37
28
|
name: nokogiri
|
38
|
-
requirement:
|
39
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
40
30
|
requirements:
|
41
31
|
- - ~>
|
42
32
|
- !ruby/object:Gem::Version
|
43
33
|
version: '1.4'
|
44
34
|
type: :runtime
|
45
35
|
prerelease: false
|
46
|
-
version_requirements:
|
47
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.4'
|
41
|
+
description: Parse Core Data models.
|
48
42
|
email: m@mattt.me
|
49
43
|
executables: []
|
50
44
|
extensions: []
|
51
45
|
extra_rdoc_files: []
|
52
46
|
files:
|
53
|
-
- ./core_data-0.0.1.gem
|
54
|
-
- ./core_data-0.0.2.gem
|
55
|
-
- ./core_data-0.0.3.gem
|
56
47
|
- ./core_data.gemspec
|
57
48
|
- ./Gemfile
|
58
49
|
- ./Gemfile.lock
|
59
|
-
- ./lib/core_data/attribute.rb
|
50
|
+
- ./lib/core_data/data_model/attribute.rb
|
51
|
+
- ./lib/core_data/data_model/entity.rb
|
52
|
+
- ./lib/core_data/data_model/relationship.rb
|
60
53
|
- ./lib/core_data/data_model.rb
|
61
|
-
- ./lib/core_data/
|
62
|
-
- ./lib/core_data/relationship.rb
|
54
|
+
- ./lib/core_data/version.rb
|
63
55
|
- ./lib/core_data.rb
|
64
56
|
- ./LICENSE
|
65
57
|
- ./Rakefile
|
66
58
|
- ./README.md
|
67
59
|
homepage: http://mattt.me
|
68
|
-
licenses:
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
69
63
|
post_install_message:
|
70
64
|
rdoc_options: []
|
71
65
|
require_paths:
|
72
66
|
- lib
|
73
67
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
68
|
requirements:
|
76
69
|
- - ! '>='
|
77
70
|
- !ruby/object:Gem::Version
|
78
71
|
version: '0'
|
79
|
-
segments:
|
80
|
-
- 0
|
81
|
-
hash: 592320479535591700
|
82
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
-
none: false
|
84
73
|
requirements:
|
85
74
|
- - ! '>='
|
86
75
|
- !ruby/object:Gem::Version
|
87
76
|
version: '0'
|
88
|
-
segments:
|
89
|
-
- 0
|
90
|
-
hash: 592320479535591700
|
91
77
|
requirements: []
|
92
78
|
rubyforge_project:
|
93
|
-
rubygems_version:
|
79
|
+
rubygems_version: 2.0.3
|
94
80
|
signing_key:
|
95
|
-
specification_version:
|
81
|
+
specification_version: 4
|
96
82
|
summary: Core Data
|
97
83
|
test_files: []
|
data/core_data-0.0.1.gem
DELETED
Binary file
|
data/core_data-0.0.2.gem
DELETED
Binary file
|
data/core_data-0.0.3.gem
DELETED
Binary file
|
data/lib/core_data/attribute.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module CoreData
|
2
|
-
class Attribute
|
3
|
-
attr_reader :name, :type, :identifier, :version_hash_modifier, :default_value
|
4
|
-
|
5
|
-
def initialize(attribute)
|
6
|
-
raise ArgumentError unless ::Nokogiri::XML::Element === attribute
|
7
|
-
|
8
|
-
@name = attribute['name']
|
9
|
-
@type = attribute['attributeType']
|
10
|
-
@identifier = attribute['elementID']
|
11
|
-
@version_hash_modifier = attribute['versionHashModifier']
|
12
|
-
@default_value = case @type
|
13
|
-
when "Integer 16", "Integer 32", "Integer 64"
|
14
|
-
attribute['defaultValueString'].to_i
|
15
|
-
when "Float", "Decimal"
|
16
|
-
attribute['defaultValueString'].to_f
|
17
|
-
end if attribute['defaultValueString']
|
18
|
-
|
19
|
-
@optional = attribute['optional'] == "YES"
|
20
|
-
@transient = attribute['transient'] == "YES"
|
21
|
-
@indexed = attribute['indexed'] == "YES"
|
22
|
-
@syncable = attribute['syncable'] == "YES"
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_s
|
26
|
-
@name
|
27
|
-
end
|
28
|
-
|
29
|
-
[:optional, :transient, :indexed, :syncable].each do |symbol|
|
30
|
-
define_method("#{symbol}?") {!!instance_variable_get(("@#{symbol}").intern)}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/core_data/entity.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module CoreData
|
2
|
-
class Entity
|
3
|
-
attr_reader :name, :attributes, :relationships
|
4
|
-
|
5
|
-
def initialize(entity)
|
6
|
-
raise ArgumentError unless ::Nokogiri::XML::Element === entity
|
7
|
-
|
8
|
-
@name = entity['name']
|
9
|
-
@attributes = entity.xpath('attribute').collect{|element| Attribute.new(element)}
|
10
|
-
@relationships = entity.xpath('relationship').collect{|element| Relationship.new(element)}
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_s
|
14
|
-
@name
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module CoreData
|
2
|
-
class Relationship
|
3
|
-
attr_reader :name, :destination, :inverse, :deletion_rule, :min_count, :max_count
|
4
|
-
|
5
|
-
def initialize(relationship)
|
6
|
-
raise ArgumentError unless ::Nokogiri::XML::Element === relationship
|
7
|
-
|
8
|
-
@name = relationship['name']
|
9
|
-
@destination = relationship['destinationEntity']
|
10
|
-
@inverse = relationship['inverseName']
|
11
|
-
@deletion_rule = relationship['deletionRule'].downcase.to_sym
|
12
|
-
|
13
|
-
@min_count = relationship['minCount'].to_i
|
14
|
-
@max_count = relationship['maxCount'].to_i
|
15
|
-
|
16
|
-
@to_many = relationship['toMany'] == "YES"
|
17
|
-
@optional = relationship['optional'] == "YES"
|
18
|
-
@syncable = relationship['syncable'] == "YES"
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_s
|
22
|
-
@name
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_many?
|
26
|
-
!!@to_many
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_one?
|
30
|
-
!to_many?
|
31
|
-
end
|
32
|
-
|
33
|
-
[:optional, :syncable].each do |symbol|
|
34
|
-
define_method("#{symbol}?") {!!instance_variable_get(("@#{symbol}").intern)}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|