Skip to content

Commit

Permalink
Updates for RDF 3.1 release and Ruby 2.7 calling sequences.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Dec 16, 2019
1 parent aeec0a8 commit e12d165
Show file tree
Hide file tree
Showing 72 changed files with 425 additions and 324 deletions.
108 changes: 108 additions & 0 deletions .byebug_history
@@ -0,0 +1,108 @@
c
subject.query({subject: Cars.car3, predicate: RDF.type, object: Cars.car})
subject.query({subject: Cars.car3, predicate: RDF.type, object: Cars.car3})
subject.query({subject: Cars.car3, predicate: RDF.type}).to_a
subject.query({subject: Cars.car2}).to_a
subject.query({subject: Cars.car2, predicate: RDF.type}).to_a
subject.query({subject: Cars.car2, predicate: RDF.type})
subject.query({subject: Cars.car2, predicate: RDF.type, object: Cars.car3})
subject.query({subject: Cars.car2, predicate: RDF.type, object: Cars.car})
Cars.car3.attributes
Cars.car3
car3.attributes
puts subject.dump(:ttl)
subject.count
subject
c
objects
n
options[:predicate]
n
name
n
s
sts.to_a
sts
n
s
n
s
person.attributes
person
c
p.attributes
n
exit
props
n
s
Person.new(name: "Dick").attributes
friend.attributes
friend
exit
self.class.repository.dump(:ttl)
self.class.repository
self.class.repository.query({subject: subject}).to_a
s
n
s
c
sts.to_a
sts
name
sts.to_a
sts
objects
n
options
s
n
s
n
s
exit
self.class.properties
options
options[:predicate]
n
options
name
s
self.class.properties
sts
n
s
attributes
n
s
attributes
n
s
c
props
self.attributes
self
n
s
c
person.attributes
person
person.name
person.reload
person.reolad
c
person
n
value
n
@attrs[name]
n
s
self.class.properties[name]
self.class.properties
n
name
s
name
n
s
12 changes: 3 additions & 9 deletions .travis.yml
@@ -1,21 +1,15 @@
language: ruby
bundler_args: --without debug
script: "bundle exec rake spec"
before_install:
- 'gem update --system --conservative || (gem i "rubygems-update:~>2.7" --no-document && update_rubygems)'
- 'gem update bundler --conservative'
env:
- CI=true
rvm:
- 2.2
- 2.3
- 2.4
- 2.5
- 2.6
- jruby-9
- rbx-3
- 2.7
- jruby
matrix:
allow_failures:
- rvm: jruby-9
- rvm: rbx-3
- rvm: jruby
sudo: false
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -17,8 +17,8 @@ group :development, :test do
end

group :test do
gem 'coveralls', :require => false
gem 'simplecov', '~> 0.10', :require => false
gem 'simplecov', platforms: :mri
gem 'coveralls', '~> 0.8', platforms: :mri
gem 'guard' #, '~> 2.13.0'
gem 'guard-rspec' #, '~> 3.1.0'
gem 'guard-ctags-bundler' #, '~> 1.4.0'
Expand Down
2 changes: 1 addition & 1 deletion Guardfile
@@ -1,4 +1,4 @@
guard "ctags-bundler", :emacs => true do
guard "ctags-bundler", emacs: true do
watch(/^(lib|spec\/support)\/.*\.rb$/)
watch("Gemfile.lock")
end
Expand Down
38 changes: 19 additions & 19 deletions README.md
Expand Up @@ -25,10 +25,10 @@ require 'rdf/vocab'

class Person < Spira::Base

configure :base_uri => "http://example.org/example/people"
configure base_uri: "http://example.org/example/people"

property :name, :predicate => RDF::Vocab::FOAF.name, :type => String
property :age, :predicate => RDF::Vocab::FOAF.age, :type => Integer
property :name, predicate: RDF::Vocab::FOAF.name, type: String
property :age, predicate: RDF::Vocab::FOAF.age, type: Integer

end

Expand Down Expand Up @@ -116,15 +116,15 @@ require 'spira'
require 'rdf/vocab'

class CD < Spira::Base
configure :base_uri => 'http://example.org/cds'
property :name, :predicate => RDF::Vocab::DC.title, :type => XSD.string
property :artist, :predicate => RDF::URI.new('http://example.org/vocab/artist'), :type => :artist
configure base_uri: 'http://example.org/cds'
property :name, predicate: RDF::Vocab::DC.title, type: XSD.string
property :artist, predicate: RDF::URI.new('http://example.org/vocab/artist'), type: :artist
end

class Artist < Spira::Base
configure :base_uri => 'http://example.org/artists'
property :name, :predicate => RDF::Vocab::DC.title, :type => XSD.string
has_many :cds, :predicate => RDF::URI.new('http://example.org/vocab/published_cd'), :type => XSD.string
configure base_uri: 'http://example.org/artists'
property :name, predicate: RDF::Vocab::DC.title, type: XSD.string
has_many :cds, predicate: RDF::URI.new('http://example.org/vocab/published_cd'), type: XSD.string
end
```

Expand Down Expand Up @@ -219,7 +219,7 @@ require 'rdf/vocab'

class Album < Spira::Base
type RDF::URI.new('http://example.org/types/album')
property :name, :predicate => RDF::Vocab::DC.title
property :name, predicate: RDF::Vocab::DC.title
end

Spira.repository = RDF::Repository.new
Expand Down Expand Up @@ -270,10 +270,10 @@ A class with a `default_vocabulary` set will transparently create predicates for

```ruby
class Song < Spira::Base
configure :default_vocabulary => RDF::URI.new('http://example.org/vocab'),
:base_uri => 'http://example.org/songs'
configure default_vocabulary: RDF::URI.new('http://example.org/vocab'),
base_uri: 'http://example.org/songs'
property :title
property :author, :type => :artist
property :author, type: :artist
end

Spira.repository = RDF::Repository.new
Expand All @@ -295,8 +295,8 @@ will always return a list, including an empty list for no value. All options
for `property` work for `has_many`.

```ruby
property :artist, :type => :artist #=> cd.artist returns a single value
has_many :cds, :type => :cd #=> artist.cds returns an array
property :artist, type: :artist #=> cd.artist returns a single value
has_many :cds, type: :cd #=> artist.cds returns an array
```

Property always takes a symbol name as a name, and a variable list of options. The supported options are:
Expand All @@ -315,7 +315,7 @@ properties having a single item, ie defined with `property`.

```ruby
class Article < Spira::Base
property :label, :localized => true
property :label, localized: true
end

Spira.repository = RDF::Repository.new
Expand Down Expand Up @@ -375,8 +375,8 @@ Classes can now use this particular type like so:

```ruby
class Test < Spira::Base
property :test1, :type => Integer
property :test2, :type => RDF::XSD.integer
property :test1, type: Integer
property :test2, type: RDF::XSD.integer
end
```

Expand Down Expand Up @@ -411,7 +411,7 @@ module MyModule
end

class MyClass < Spira::Base
property :property1, :type => MyModule::MyType
property :property1, type: MyModule::MyType
end
```

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Expand Up @@ -35,7 +35,7 @@ task :console do
sh "irb -rubygems -I lib -r spira -I spec/fixtures -r person -r event -r cds -r cars -r posts -I spec -r spec_helper -r loading"
end

task :default => [:spec]
task default: [:spec]

desc "Add analytics tracking information to yardocs"
task :addanalytics do
Expand Down Expand Up @@ -64,6 +64,6 @@ EOC
end

desc "Upload docs to rubyforge"
task :uploadyardocs => [:yardoc, :addanalytics] do
task uploadyardocs: [:yardoc, :addanalytics] do
`rsync -av doc/yard/* bhuga@rubyforge.org:/var/www/gforge-projects/spira`
end
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
3.1.0
3.1.1
8 changes: 4 additions & 4 deletions lib/spira/base.rb
Expand Up @@ -93,7 +93,7 @@ def inherited(child)
end

def instantiate_record(subj)
new(:_subject => id_for(subj))
new(_subject: id_for(subj))
end

end # class methods
Expand Down Expand Up @@ -260,7 +260,7 @@ def to_node
# @param [RDF::Resource] new_subject
# @return [Spira::Base] copy
def copy(new_subject)
self.class.new(@attrs.merge(:_subject => new_subject))
self.class.new(@attrs.merge(_subject: new_subject))
end

##
Expand Down Expand Up @@ -336,7 +336,7 @@ def merge_localized_property(name, arg)
end

def serialize_localized_property(value, locale)
RDF::Literal.new(value, :language => locale)
RDF::Literal.new(value, language: locale)
end

def unserialize_localized_properties(values, locale)
Expand All @@ -352,7 +352,7 @@ def hash_localized_properties(values)
end

def serialize_hash_localized_properties(values)
values.map { |lang, property| RDF::Literal.new(property, :language => lang) }
values.map { |lang, property| RDF::Literal.new(property, language: lang) }
end

# Build a Ruby value from an RDF value.
Expand Down
22 changes: 11 additions & 11 deletions lib/spira/persistence.rb
Expand Up @@ -20,7 +20,7 @@ def repository
# @param [Hash] args
# args can contain:
# :conditions - Hash of properties and values
# :limit - Fixnum, limiting the amount of returned records
# :limit - Integer, limiting the amount of returned records
# @return [Spira::Base, Array]
def find(scope, *args)
case scope
Expand Down Expand Up @@ -73,7 +73,7 @@ def each(*args)
# cannot handle such patterns, we iterate across types "manually"
types.each do |tp|
break if limit.zero?
q = conditions_to_query(conditions.merge(:type => tp))
q = conditions_to_query(conditions.merge(type: tp))
repository.query(q) do |solution|
break if limit.zero?
if offset.zero?
Expand Down Expand Up @@ -112,24 +112,24 @@ def count
#
# ==== Examples
# # Create a single new object
# User.create(:first_name => 'Jamie')
# User.create(first_name: 'Jamie')
#
# # Create a single new object using the :admin mass-assignment security role
# User.create({ :first_name => 'Jamie', :is_admin => true }, :as => :admin)
# User.create({ first_name: 'Jamie', is_admin: true }, as: :admin)
#
# # Create a single new object bypassing mass-assignment security
# User.create({ :first_name => 'Jamie', :is_admin => true }, :without_protection => true)
# User.create({ first_name: 'Jamie', is_admin: true }, without_protection: true)
#
# # Create an Array of new objects
# User.create([{ :first_name => 'Jamie' }, { :first_name => 'Jeremy' }])
# User.create([{ first_name: 'Jamie' }, { first_name: 'Jeremy' }])
#
# # Create a single object and pass it into a block to set other attributes.
# User.create(:first_name => 'Jamie') do |u|
# User.create(first_name: 'Jamie') do |u|
# u.is_admin = false
# end
#
# # Creating an Array of new objects using a block, where the block is executed for each object:
# User.create([{ :first_name => 'Jamie' }, { :first_name => 'Jeremy' }]) do |u|
# User.create([{ first_name: 'Jamie' }, { first_name: 'Jeremy' }]) do |u|
# u.is_admin = false
# end
def create(attributes = nil, options = {}, &block)
Expand Down Expand Up @@ -192,7 +192,7 @@ def for(identifier, attributes = {}, &block)
# @param [Hash{Symbol => Any}] attributes Initial attributes
# @return [Spira::Base] the newly created instance
def project(subject, attributes = {}, &block)
new(attributes.merge(:_subject => subject), &block)
new(attributes.merge(_subject: subject), &block)
end

##
Expand Down Expand Up @@ -342,7 +342,7 @@ def count
# Update multiple attributes of this repository.
#
# @example Update multiple attributes
# person.update_attributes(:name => 'test', :age => 10)
# person.update_attributes(name: 'test', age: 10)
# #=> person
# person.name
# #=> 'test'
Expand All @@ -366,7 +366,7 @@ def update_attributes(properties, options = {})
# NB: "props" argument is ignored, it is handled in Base
#
def reload(props = {})
sts = self.class.repository.query(:subject => subject)
sts = self.class.repository.query({subject: subject})
self.class.properties.each do |name, options|
name = name.to_s
if sts
Expand Down

0 comments on commit e12d165

Please sign in to comment.