Skip to content

Commit 1aa855f

Browse files
committed
Release 3.1.0:
* Add support of activemodel 5.2
2 parents 25efccc + 87b2ad7 commit 1aa855f

File tree

9 files changed

+38
-36
lines changed

9 files changed

+38
-36
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.0
1+
3.1.0

lib/spira/base.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class Base
3232
# @return [RDF::URI]
3333
attr_reader :subject
3434

35-
attr_accessor :attributes
36-
3735
class << self
3836
attr_reader :reflections, :properties
3937

@@ -119,21 +117,26 @@ def id
119117
# @see RDF::Node#as
120118
def initialize(props = {}, options = {})
121119
@subject = props.delete(:_subject) || RDF::Node.new
120+
@attrs = {}
122121

123-
@attributes = {}
124122
reload props
125123

126124
yield self if block_given?
127125
end
128126

127+
# Returns the attributes
128+
def attributes
129+
@attrs
130+
end
131+
129132
# Freeze the attributes hash such that associations are still accessible, even on destroyed records.
130133
def freeze
131-
@attributes.freeze; self
134+
@attrs.freeze; self
132135
end
133136

134137
# Returns +true+ if the attributes hash has been frozen.
135138
def frozen?
136-
@attributes.frozen?
139+
@attrs.frozen?
137140
end
138141

139142
##
@@ -257,7 +260,7 @@ def to_node
257260
# @param [RDF::Resource] new_subject
258261
# @return [Spira::Base] copy
259262
def copy(new_subject)
260-
self.class.new(attributes.merge(:_subject => new_subject))
263+
self.class.new(@attrs.merge(:_subject => new_subject))
261264
end
262265

263266
##
@@ -284,20 +287,19 @@ def assign_attributes(attrs)
284287
private
285288

286289
def reset_changes
287-
@previously_changed = changes
288-
@changed_attributes.clear
290+
clear_changes_information
289291
end
290292

291293
def write_attribute(name, value)
292294
name = name.to_s
293295
if self.class.properties[name]
294-
if attributes[name].is_a?(Promise)
295-
changed_attributes[name] = attributes[name] unless changed_attributes.include?(name)
296-
attributes[name] = value
296+
if @attrs[name].is_a?(Promise)
297+
changed_attributes[name] = @attrs[name] unless changed_attributes.include?(name)
298+
@attrs[name] = value
297299
else
298300
if value != read_attribute(name)
299301
attribute_will_change!(name)
300-
attributes[name] = value
302+
@attrs[name] = value
301303
end
302304
end
303305
else
@@ -309,7 +311,7 @@ def write_attribute(name, value)
309311
# Get the current value for the given attribute
310312
#
311313
def read_attribute(name)
312-
value = attributes[name.to_s]
314+
value = @attrs[name.to_s]
313315

314316
refl = self.class.reflections[name]
315317
if refl && !value

spec/base_uri_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ::HashBaseURITest < Spira::Base
7474
context "classes without a base URI" do
7575
before :all do
7676
class ::NoBaseURITest < Spira::Base
77-
property :name, :predicate => RDFS.label
77+
property :name, :predicate => RDF::RDFS.label
7878
end
7979
end
8080

spec/non_model_data_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ::ExtraDataTest < Spira::Base
77
configure :base_uri => "http://example.org/example"
88

99
property :property, :predicate => RDF::Vocab::FOAF.age, :type => Integer
10-
has_many :list, :predicate => RDFS.label
10+
has_many :list, :predicate => RDF::RDFS.label
1111
end
1212
end
1313
let(:extra_repo) {RDF::Repository.load(fixture('non_model_data.nt'))}

spec/psych_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
before :all do
99
class PsychPerson < Spira::Base
1010
configure :base_uri => "http://example.org/example/people"
11-
property :name, :predicate => RDFS.label
11+
property :name, :predicate => RDF::RDFS.label
1212
property :age, :predicate => RDF::Vocab::FOAF.age, :type => Integer
1313
end
14-
14+
1515
class PsychEmployee < Spira::Base
16-
property :name, :predicate => RDFS.label
16+
property :name, :predicate => RDF::RDFS.label
1717
property :age, :predicate => RDF::Vocab::FOAF.age, :type => Integer
1818
end
1919

spec/rdf_types_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require "spec_helper"
2-
# These classes are to test finding based on rdfs.type
2+
# These classes are to test finding based on RDF::RDFS.type
33

44

55
class Cars < RDF::Vocabulary('http://example.org/cars/')
@@ -19,16 +19,16 @@ class Cars < RDF::Vocabulary('http://example.org/cars/')
1919
before :all do
2020
class ::Car < Spira::Base
2121
type Cars.car
22-
property :name, :predicate => RDFS.label
22+
property :name, :predicate => RDF::RDFS.label
2323
end
24-
24+
2525
class ::Van < Spira::Base
2626
type Cars.van
27-
property :name, :predicate => RDFS.label
27+
property :name, :predicate => RDF::RDFS.label
2828
end
29-
29+
3030
class ::Wagon < Spira::Base
31-
property :name, :predicate => RDFS.label
31+
property :name, :predicate => RDF::RDFS.label
3232
end
3333

3434
class ::MultiCar < Spira::Base
@@ -51,7 +51,7 @@ class ::XYZ < Spira::Base
5151
it "should provide a class method which returns the type" do
5252
expect(Car).to respond_to :type
5353
end
54-
54+
5555
it "should return the correct type" do
5656
expect(Car.type).to eql Cars.car
5757
end

spec/relations_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
describe "Spira resources" do
44

55
before :all do
6-
6+
77
class ::CDs < RDF::Vocabulary('http://example.org/')
88
property :artist
99
property :cds
1010
property :artists
1111
property :has_cd
1212
end
13-
13+
1414
class ::CD < Spira::Base
1515
configure :base_uri => CDs.cds
1616
property :name, :predicate => RDF::Vocab::DC.title, :type => String
1717
property :artist, :predicate => CDs.artist, :type => 'Artist'
1818
end
19-
19+
2020
class ::Artist < Spira::Base
2121
configure :base_uri => CDs.artists
2222
property :name, :predicate => RDF::Vocab::DC.title, :type => String
@@ -45,7 +45,7 @@ class ::RootNSTest < Spira::Base
4545
test.name = RootNSTest.new
4646
test.name.save!
4747
test.save!
48-
48+
4949
test = subject.as(RootNSTest)
5050
expect(test.name).to be_a RootNSTest
5151
end
@@ -86,7 +86,7 @@ module ::NSTestA
8686
class A < Spira::Base
8787
end
8888
end
89-
end
89+
end
9090

9191
it "should find a class based on the string version of the name" do
9292
test = NSTest::Z.new
@@ -129,7 +129,7 @@ class A < Spira::Base
129129
context "with a one-to-many relationship" do
130130
subject(:artist) {Artist.for "nirvana"}
131131
subject(:cd) {CD.for 'nevermind'}
132-
132+
133133
before :each do
134134
Spira.repository = RDF::Repository.load(fixture('relations.nt'))
135135
@cd = CD.for 'nevermind'
@@ -188,7 +188,7 @@ class A < Spira::Base
188188
before {Spira.repository = invalid_repo}
189189

190190
context "when accessing a field named for a non-existant class" do
191-
191+
192192
before do
193193
class ::RelationsTestA < Spira::Base
194194
configure :base_uri => CDs.cds
@@ -218,7 +218,7 @@ class ::RelationsTestB < Spira::Base
218218
property :invalid, :predicate => RDF::Vocab::DC.title, :type => 'Object'
219219
end
220220
end
221-
221+
222222
it "should should raise a TypeError when saving an object with the invalid property" do
223223
expect { RelationsTestB.new(:invalid => Object.new).save! }.to raise_error TypeError
224224
end

spec/update_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
before :all do
88
class ::UpdateTest < Spira::Base
99
configure :base_uri => "http://example.org/example/people"
10-
property :name, :predicate => RDFS.label
10+
property :name, :predicate => RDF::RDFS.label
1111
property :age, :predicate => RDF::Vocab::FOAF.age, :type => Integer
1212
end
1313
end

spec/validations_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class ::Bank < Spira::Base
99
configure :default_vocabulary => RDF::URI.new('http://example.org/banks/vocab')
1010

11-
property :title, :predicate => RDFS.label
11+
property :title, :predicate => RDF::RDFS.label
1212
property :balance, :type => Integer
1313

1414
validate :validate_bank

0 commit comments

Comments
 (0)