core_data 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +20 -0
- data/LICENSE +19 -0
- data/README.md +29 -0
- data/Rakefile +10 -0
- data/core_data.gemspec +24 -0
- data/lib/core_data/attribute.rb +27 -0
- data/lib/core_data/data_model.rb +25 -0
- data/lib/core_data/entity.rb +17 -0
- data/lib/core_data/relationship.rb +37 -0
- data/lib/core_data.rb +10 -0
- metadata +94 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
core_data (0.0.1)
|
5
|
+
nokogiri (~> 1.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
nokogiri (1.5.5)
|
11
|
+
rake (0.9.2.2)
|
12
|
+
rspec (0.6.4)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
core_data!
|
19
|
+
rake (~> 0.9.2)
|
20
|
+
rspec (~> 0.6.1)
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 Mattt Thompson (http://mattt.me/)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# CoreData
|
2
|
+
**A Gem for Interacting with Core Data Models**
|
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
|
+
```
|
18
|
+
|
19
|
+
## Contact
|
20
|
+
|
21
|
+
Mattt Thompson
|
22
|
+
|
23
|
+
- http://github.com/mattt
|
24
|
+
- http://twitter.com/mattt
|
25
|
+
- m@mattt.me
|
26
|
+
|
27
|
+
## License
|
28
|
+
|
29
|
+
CoreData is available under the MIT license. See the LICENSE file for more info.
|
data/Rakefile
ADDED
data/core_data.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "core_data"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "core_data"
|
7
|
+
s.authors = ["Mattt Thompson"]
|
8
|
+
s.email = "m@mattt.me"
|
9
|
+
s.homepage = "http://mattt.me"
|
10
|
+
s.version = CoreData::VERSION
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.summary = "Core Data"
|
13
|
+
s.description = "A gem for interacting with Core Data models"
|
14
|
+
|
15
|
+
s.add_development_dependency "rspec", "~> 0.6.1"
|
16
|
+
s.add_development_dependency "rake", "~> 0.9.2"
|
17
|
+
|
18
|
+
s.add_dependency "nokogiri", "~> 1.4"
|
19
|
+
|
20
|
+
s.files = Dir["./**/*"].reject { |file| file =~ /\.\/(bin|log|pkg|script|spec|test|vendor)/ }
|
21
|
+
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 = ["lib"]
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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
|
+
|
13
|
+
@optional = attribute['optional'] == "YES"
|
14
|
+
@transient = attribute['transient'] == "YES"
|
15
|
+
@indexed = attribute['indexed'] == "YES"
|
16
|
+
@syncable = attribute['syncable'] == "YES"
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
@name
|
21
|
+
end
|
22
|
+
|
23
|
+
[:optional, :transient, :indexed, :syncable].each do |symbol|
|
24
|
+
define_method("#{symbol}?") {!!instance_variable_get(("@#{symbol}").intern)}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CoreData
|
2
|
+
class DataModel
|
3
|
+
attr_reader :name, :version, :entities
|
4
|
+
|
5
|
+
def initialize(xcdatamodel)
|
6
|
+
loop do
|
7
|
+
case xcdatamodel
|
8
|
+
when File, /^\<\?xml/
|
9
|
+
xcdatamodel = ::Nokogiri::XML(xcdatamodel) and redo
|
10
|
+
when String
|
11
|
+
xcdatamodel = ::File.read(xcdatamodel) and redo
|
12
|
+
when ::Nokogiri::XML::Document
|
13
|
+
break
|
14
|
+
else
|
15
|
+
raise ArgumentError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
model = xcdatamodel.at_xpath('model')
|
20
|
+
@name = model['name']
|
21
|
+
@version = model['systemVersion']
|
22
|
+
@entities = model.xpath('entity').collect{|element| Entity.new(element)}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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
|
@@ -0,0 +1,37 @@
|
|
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
|
+
@optional = 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
|
data/lib/core_data.rb
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: core_data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mattt Thompson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-18 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70152201873960 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.6.1
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70152201873960
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &70152201872480 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.9.2
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70152201872480
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: nokogiri
|
38
|
+
requirement: &70152201871160 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.4'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70152201871160
|
47
|
+
description: A gem for interacting with Core Data models
|
48
|
+
email: m@mattt.me
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- ./core_data.gemspec
|
54
|
+
- ./Gemfile
|
55
|
+
- ./Gemfile.lock
|
56
|
+
- ./lib/core_data/attribute.rb
|
57
|
+
- ./lib/core_data/data_model.rb
|
58
|
+
- ./lib/core_data/entity.rb
|
59
|
+
- ./lib/core_data/relationship.rb
|
60
|
+
- ./lib/core_data.rb
|
61
|
+
- ./LICENSE
|
62
|
+
- ./Rakefile
|
63
|
+
- ./README.md
|
64
|
+
homepage: http://mattt.me
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
hash: -1634406435194911796
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
hash: -1634406435194911796
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.8.15
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Core Data
|
94
|
+
test_files: []
|