kalimba 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51492726fdd0d0303d00af8376c1bef0af951d48
4
- data.tar.gz: c4bdf88223e9efd0591d447a152b9f16896d0626
3
+ metadata.gz: 7fd069de6d00e1c65056fff0475c77f7fdaee85d
4
+ data.tar.gz: af303d1b91dec1a12f2d98eb34d5fbd725092460
5
5
  SHA512:
6
- metadata.gz: 1543ecdd70a064ca87f4328d5e6729297d28cc93174917c2907911512191746b28c0bff95bcff08fe190956522bb6926c515231541e986ce0bc6ccb04af5304e
7
- data.tar.gz: 61c0b9a9a146b8da73499ea763b21a02e2405fda113c2dd8ba589479f126d61ea9bffaadda60e17fffe0bf71768732f85a64ddff88b653f86be84ae3278cecc7
6
+ metadata.gz: 83c57ef31bf5328e4db51c63cfe1536c7c8610603f7b50ebb85be9319f33e6c4d8ed9646a723db97b4020d608770b6440a93d275c07a77cb3897c2146b1435cf
7
+ data.tar.gz: 386202bcead3ac436ca01dd2a25914a507cb99dcdc6932af5772f0e9e96efe2cfacbe43c49b03f2a9cb6f7167f2dac3c3d5f9bbbb70eaae23306d159c34f7816
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Slava Kravchenko
1
+ Copyright (c) 2012, 2013 Slava Kravchenko
2
2
 
3
3
  MIT License
4
4
 
@@ -9,8 +9,8 @@ module Kalimba
9
9
  @reflections ||= {}
10
10
  end
11
11
 
12
- def create_reflection(name, params = {})
13
- reflections[name] = AssociationReflection.new(name, {class_name: params[:datatype]})
12
+ def create_reflection(name, klass)
13
+ reflections[name] = AssociationReflection.new(name, {class_name: klass})
14
14
  end
15
15
 
16
16
  def reflect_on_association(association)
@@ -96,24 +96,18 @@ module Kalimba
96
96
  name = name.to_s
97
97
 
98
98
  params[:predicate] = URI(params[:predicate])
99
- association = Kalimba::Resource.from_datatype(params[:datatype])
100
- if association
101
- params[:datatype] = association.type
102
- class_eval <<-HERE, __FILE__, __LINE__
103
- def #{name}_id
104
- self.#{name}.try(:id)
105
- end
106
-
107
- def #{name}_id=(value)
108
- self.#{name} = value.blank? ? nil : #{association}.for(value)
109
- end
110
- HERE
99
+ association_class = Kalimba::Resource.from_datatype(params[:datatype])
100
+ if association_class
101
+ params[:datatype] = association_class
102
+ if params[:collection]
103
+ define_collection(name, association_class)
104
+ else
105
+ define_resource(name, association_class)
106
+ end
111
107
  else
112
108
  params[:datatype] = URI(params[:datatype])
113
109
  end
114
110
 
115
- define_collection(name, params) if params[:collection]
116
-
117
111
  self.properties[name] = params
118
112
 
119
113
  define_attribute_method name if self.is_a?(Class)
@@ -152,6 +146,9 @@ module Kalimba
152
146
  # @example
153
147
  # has_many :duties, :predicate => "http://works.com#duty", :datatype => NS::XMLSchema["string"]
154
148
  #
149
+ # Note however, that if given datatype does not refer to a Kalimba::Resource class,
150
+ # no reflections and `_ids` and `_ids=` accessors will be created in that case.
151
+ #
155
152
  # @param (see #property)
156
153
  def has_many(name, params = {})
157
154
  property name, params.merge(:collection => true)
@@ -162,6 +159,8 @@ module Kalimba
162
159
  # @param [String, URI, Symbol] uri
163
160
  # @return [Kalimba::Resource]
164
161
  def from_datatype(datatype)
162
+ return datatype if datatype.is_a?(Class) && datatype.ancestors.include?(Kalimba::Resource)
163
+
165
164
  datatype =
166
165
  case datatype
167
166
  when URI
@@ -192,8 +191,21 @@ module Kalimba
192
191
  child.properties = properties.dup
193
192
  end
194
193
 
195
- def define_collection(name, params)
196
- create_reflection(name, params)
194
+ def define_resource(name, klass)
195
+ class_eval <<-HERE, __FILE__, __LINE__
196
+ def #{name}_id
197
+ self.#{name}.try(:id)
198
+ end
199
+
200
+ def #{name}_id=(value)
201
+ self.#{name} = value.blank? ? nil : #{klass}.for(value)
202
+ end
203
+ HERE
204
+ end
205
+
206
+ def define_collection(name, klass)
207
+ # Rails reflections require symbolized names
208
+ create_reflection(name.to_sym, klass)
197
209
 
198
210
  class_eval <<-HERE, __FILE__, __LINE__
199
211
  def #{name.singularize}_ids
@@ -258,6 +270,19 @@ module Kalimba
258
270
  subject
259
271
  end
260
272
 
273
+ # Resource equality
274
+ #
275
+ # Two Kalimba resources are equal if their subjects are equal.
276
+ # We do not tell between persisted or not persisted RDF resources.
277
+ # However, "new" resources (those without a subject) are never equal.
278
+ #
279
+ # @param [Kalimba::Resource] other other Kalimba::Resource
280
+ # @return [Boolean]
281
+ def eql?(other)
282
+ other.is_a?(Kalimba::Resource) && !subject.nil? && other.subject == subject
283
+ end
284
+ alias == eql?
285
+
261
286
  private
262
287
 
263
288
  include Kalimba::Callbacks
@@ -1,3 +1,3 @@
1
1
  module Kalimba
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -260,7 +260,7 @@ describe Kalimba::Persistence do
260
260
  end
261
261
  end
262
262
 
263
- context "to collections" do
263
+ context "to collections of non-Kalimba resources" do
264
264
  before { person.duties = %w(building designing) }
265
265
 
266
266
  context "when saved" do
@@ -269,6 +269,27 @@ describe Kalimba::Persistence do
269
269
  it "should be added statements with changed attributes (type + duties*2)" do
270
270
  expect(Kalimba.repository.size).to eql 3
271
271
  end
272
+
273
+ it "should include the collection" do
274
+ person.reload
275
+ expect(person.duties).to eql %w(building designing)
276
+ end
277
+ end
278
+ end
279
+
280
+ context "to collections of Kalimba resources" do
281
+ before do
282
+ @berk = Engineer.for("Berk")
283
+ person.coworkers = [@berk]
284
+ end
285
+
286
+ context "when saved" do
287
+ before { person.save }
288
+
289
+ it "should retain the list of coworkers" do
290
+ person.reload
291
+ expect(person.coworkers).to eql [@berk]
292
+ end
272
293
  end
273
294
  end
274
295
  end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ describe "reflection" do
4
+ before :all do
5
+ class ReflectionTestOilRig < Kalimba::Resource
6
+ type "http://schema.org/ReflectionTestOilRig"
7
+ base_uri "http://example.org/reflection_oil_rigs"
8
+
9
+ has_many :neighbours, :predicate => "http://example.org/reflection_oil_rigs", :datatype => :ReflectionTestOilRig
10
+ has_many :saboteurs, :predicate => "http://example.org/reflection_saboteur", :datatype => "http://schema.org/ReflectionTestSaboteur"
11
+ end
12
+ end
13
+
14
+ subject { ReflectionTestOilRig.reflections }
15
+
16
+ context "for a non-Kalimba resource" do
17
+ it { should_not have_key :saboteurs }
18
+ end
19
+
20
+ context "for a Kalimba::Resource association" do
21
+ it { should have_key :neighbours }
22
+
23
+ context ":neighbours" do
24
+ subject { ReflectionTestOilRig.reflect_on_association(:neighbours) }
25
+
26
+ it "should have proper accessors" do
27
+ expect(subject.macro).to eql :has_many
28
+ expect(subject.name).to eql :neighbours
29
+ expect(subject.klass).to eql ReflectionTestOilRig
30
+ expect(subject.class_name).to eql "ReflectionTestOilRig"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -39,6 +39,8 @@ describe Kalimba::Resource do
39
39
 
40
40
  it { should respond_to :attributes }
41
41
 
42
+ it { should_not eql ResourceTestPerson.new }
43
+
42
44
  context "created via 'for'" do
43
45
  subject { ResourceTestPerson.for "charlie" }
44
46
 
@@ -47,6 +49,8 @@ describe Kalimba::Resource do
47
49
  it "should set subject to the given URI" do
48
50
  expect(subject.subject).to eql URI("http://example.org/people/#charlie")
49
51
  end
52
+
53
+ it { should eql ResourceTestPerson.for("charlie") }
50
54
  end
51
55
 
52
56
  describe "serialization" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kalimba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Slava Kravchenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-13 00:00:00.000000000 Z
11
+ date: 2013-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -74,13 +74,9 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - .gitignore
78
- - Gemfile
79
77
  - LICENSE
80
78
  - README.md
81
79
  - Rakefile
82
- - kalimba-redlander.gemspec
83
- - kalimba.gemspec
84
80
  - lib/kalimba.rb
85
81
  - lib/kalimba/attribute_assignment.rb
86
82
  - lib/kalimba/callbacks.rb
@@ -96,12 +92,14 @@ files:
96
92
  - spec/lib/kalimba/attributes_spec.rb
97
93
  - spec/lib/kalimba/callbacks_spec.rb
98
94
  - spec/lib/kalimba/persistence_spec.rb
95
+ - spec/lib/kalimba/reflection_spec.rb
99
96
  - spec/lib/kalimba/resource_spec.rb
100
97
  - spec/lib/kalimba/validations_spec.rb
101
98
  - spec/spec_helper.rb
102
99
  - spec/support/resource_ext.rb
103
100
  homepage: https://github.com/cordawyn/kalimba
104
- licenses: []
101
+ licenses:
102
+ - The MIT License (MIT)
105
103
  metadata: {}
106
104
  post_install_message:
107
105
  rdoc_options: []
@@ -119,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
117
  version: '0'
120
118
  requirements: []
121
119
  rubyforge_project:
122
- rubygems_version: 2.0.0.rc.2
120
+ rubygems_version: 2.0.3
123
121
  signing_key:
124
122
  specification_version: 4
125
123
  summary: Kalimba provides ActiveRecord-like capabilities for RDF resources.
@@ -127,6 +125,7 @@ test_files:
127
125
  - spec/lib/kalimba/attributes_spec.rb
128
126
  - spec/lib/kalimba/callbacks_spec.rb
129
127
  - spec/lib/kalimba/persistence_spec.rb
128
+ - spec/lib/kalimba/reflection_spec.rb
130
129
  - spec/lib/kalimba/resource_spec.rb
131
130
  - spec/lib/kalimba/validations_spec.rb
132
131
  - spec/spec_helper.rb
data/.gitignore DELETED
@@ -1,22 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .rspec
4
- .bundle
5
- .config
6
- .yardoc
7
- Gemfile.lock
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp
19
- TAGS
20
- *~
21
- .*~
22
- bin/
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec name: "kalimba"
4
- gemspec name: "kalimba-redlander"
5
-
6
- gem "rake"
@@ -1,19 +0,0 @@
1
- require File.expand_path('../lib/kalimba/version', __FILE__)
2
-
3
- Gem::Specification.new do |gem|
4
- gem.name = "kalimba-redlander"
5
- gem.version = Kalimba::VERSION
6
- gem.authors = ["Slava Kravchenko"]
7
- gem.email = ["slava.kravchenko@gmail.com"]
8
- gem.description = %q{Redlander adapter for Kalimba. It provides the RDF storage backend for Kalimba.}
9
- gem.summary = %q{Redlander adapter for Kalimba}
10
- gem.homepage = "https://github.com/cordawyn/kalimba-redlander"
11
-
12
- gem.files = ["lib/kalimba/persistence/redlander.rb"]
13
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
- gem.require_paths = ["lib"]
16
-
17
- gem.add_runtime_dependency "kalimba"
18
- gem.add_runtime_dependency "redlander", "~> 0.6.0"
19
- end
@@ -1,22 +0,0 @@
1
- require File.expand_path('../lib/kalimba/version', __FILE__)
2
-
3
- Gem::Specification.new do |gem|
4
- gem.authors = ["Slava Kravchenko"]
5
- gem.email = ["slava.kravchenko@gmail.com"]
6
- gem.description = %q{ActiveModel-based framework, which allows the developer to combine RDF resources into ActiveRecord-like models.}
7
- gem.summary = %q{Kalimba provides ActiveRecord-like capabilities for RDF resources.}
8
- gem.homepage = "https://github.com/cordawyn/kalimba"
9
-
10
- gem.files = `git ls-files`.split($\) - ["lib/kalimba/persistence/redlander.rb"]
11
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
- gem.name = "kalimba"
14
- gem.require_paths = ["lib"]
15
- gem.version = Kalimba::VERSION
16
-
17
- gem.add_runtime_dependency "activemodel", "~> 3.2"
18
- gem.add_runtime_dependency "activesupport", "~> 3.2"
19
-
20
- gem.add_development_dependency "rspec", "~> 2.11.0"
21
- gem.add_development_dependency "kalimba-redlander"
22
- end