Skip to content

Commit

Permalink
Merge pull request #159 from ncbo/develop
Browse files Browse the repository at this point in the history
Develop -> Master merge, Release v5.33.0
  • Loading branch information
alexskr authored Oct 7, 2024
2 parents 2cec53c + 74a012e commit f943ac3
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ruby-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby-version: ['2.7', '3.0']
ruby-version: ['3.0', '3.1']
triplestore: ['fs', 'ag']

steps:
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.8
3.0.6
46 changes: 26 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,45 +31,50 @@ GEM
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
base64 (0.2.0)
builder (3.2.4)
builder (3.3.0)
coderay (1.1.3)
concurrent-ruby (1.2.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
cube-ruby (0.0.3)
daemons (1.4.1)
docile (1.4.0)
docile (1.4.1)
domain_name (0.6.20240107)
eventmachine (1.2.7)
faraday (2.8.1)
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
faraday (2.12.0)
faraday-net_http (>= 2.0, < 3.4)
json
logger
faraday-net_http (3.3.0)
net-http
http-accept (1.7.0)
http-cookie (1.0.5)
http-cookie (1.0.7)
domain_name (~> 0.5)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
json (2.7.2)
json_pure (2.7.2)
logger (1.6.1)
macaddr (1.7.2)
systemu (~> 2.6.5)
method_source (1.1.0)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0305)
mime-types-data (3.2024.0903)
minitest (4.7.5)
multi_json (1.15.0)
mustermann (3.0.0)
mustermann (3.0.3)
ruby2_keywords (~> 0.0.1)
net-http (0.4.1)
uri
net-http-persistent (2.9.4)
netrc (0.11.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.5)
public_suffix (6.0.1)
rack (2.2.9)
rack-accept (0.4.5)
rack (>= 0.4)
Expand All @@ -81,9 +86,9 @@ GEM
rake (13.2.1)
rdf (1.0.8)
addressable (>= 2.2)
redis (5.2.0)
redis (5.3.0)
redis-client (>= 0.22.0)
redis-client (0.22.1)
redis-client (0.22.2)
connection_pool
request_store (1.7.0)
rack (>= 1.4)
Expand All @@ -92,7 +97,7 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.6)
rexml (3.3.7)
rsolr (2.6.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
Expand All @@ -104,7 +109,7 @@ GEM
simplecov-cobertura (2.1.0)
rexml
simplecov (~> 0.19)
simplecov-html (0.12.3)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
sinatra (3.2.0)
mustermann (~> 3.0)
Expand All @@ -117,8 +122,9 @@ GEM
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thread_safe (0.3.6)
tilt (2.3.0)
tilt (2.4.0)
tzinfo (0.3.62)
uri (0.13.1)
uuid (2.3.9)
macaddr (~> 1.0)

Expand All @@ -145,4 +151,4 @@ DEPENDENCIES
uuid

BUNDLED WITH
2.4.22
2.5.20
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
retries: 5

agraph-ut:
image: franzinc/agraph:v8.1.0
image: franzinc/agraph:v8.2.1
platform: linux/amd64
environment:
- AGRAPH_SUPER_USER=test
Expand Down
3 changes: 2 additions & 1 deletion goo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Gem::Specification.new do |s|
s.email = "[email protected]"
s.files = Dir["lib/**/*.rb"]
s.homepage = "http://github.com/ncbo/goo"
s.add_dependency("addressable", "~> 2.8")

s.add_dependency("addressable", "~> 2.8")
s.add_dependency("pry")
s.add_dependency("rdf", "= 1.0.8")
s.add_dependency("redis")
Expand Down
82 changes: 40 additions & 42 deletions lib/goo/base/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def valid?
self.class.attributes.each do |attr|
inst_value = self.instance_variable_get("@#{attr}")
attr_errors = Goo::Validators::Enforce.enforce(self,attr,inst_value)
unless attr_errors.nil?
validation_errors[attr] = attr_errors
end
validation_errors[attr] = attr_errors unless attr_errors.nil?
end

if !@persistent && validation_errors.length == 0
Expand All @@ -70,9 +68,7 @@ def valid?
end

def id=(new_id)
if !@id.nil? and @persistent
raise ArgumentError, "The id of a persistent object cannot be changed."
end
raise ArgumentError, "The id of a persistent object cannot be changed." if !@id.nil? and @persistent
raise ArgumentError, "ID must be an RDF::URI" unless new_id.kind_of?(RDF::URI)
@id = new_id
end
Expand Down Expand Up @@ -133,6 +129,7 @@ def unmapped_get(attribute)

def unmmaped_to_array
cpy = {}

@unmapped.each do |attr,v|
cpy[attr] = v.to_a
end
Expand All @@ -147,19 +144,15 @@ def unmapped(*args)

def delete(*args)
if self.kind_of?(Goo::Base::Enum)
unless args[0] && args[0][:init_enum]
raise ArgumentError, "Enums cannot be deleted"
end
raise ArgumentError, "Enums cannot be deleted" unless args[0] && args[0][:init_enum]
end

raise ArgumentError, "This object is not persistent and cannot be deleted" if !@persistent

if !fully_loaded?
missing = missing_load_attributes
options_load = { models: [ self ], klass: self.class, :include => missing }
if self.class.collection_opts
options_load[:collection] = self.collection
end
options_load[:collection] = self.collection if self.class.collection_opts
Goo::SPARQL::Queries.model_load(options_load)
end

Expand All @@ -175,25 +168,19 @@ def delete(*args)
end
@persistent = false
@modified = true
if self.class.inmutable? && self.class.inm_instances
self.class.load_inmutable_instances
end
self.class.load_inmutable_instances if self.class.inmutable? && self.class.inm_instances
return nil
end

def bring(*opts)
opts.each do |k|
if k.kind_of?(Hash)
k.each do |k2,v|
if self.class.handler?(k2)
raise ArgumentError, "Unable to bring a method based attr #{k2}"
end
raise ArgumentError, "Unable to bring a method based attr #{k2}" if self.class.handler?(k2)
self.instance_variable_set("@#{k2}",nil)
end
else
if self.class.handler?(k)
raise ArgumentError, "Unable to bring a method based attr #{k}"
end
raise ArgumentError, "Unable to bring a method based attr #{k}" if self.class.handler?(k)
self.instance_variable_set("@#{k}",nil)
end
end
Expand All @@ -208,9 +195,7 @@ def bring(*opts)

def graph
opts = self.class.collection_opts
if opts.nil?
return self.class.uri_type
end
return self.class.uri_type if opts.nil?
col = collection
if col.is_a?Array
if col.length == 1
Expand Down Expand Up @@ -290,9 +275,7 @@ def collection
if opts.instance_of?(Symbol)
if self.class.attributes.include?(opts)
value = self.send("#{opts}")
if value.nil?
raise ArgumentError, "Collection `#{opts}` is nil"
end
raise ArgumentError, "Collection `#{opts}` is nil" if value.nil?
return value
else
raise ArgumentError, "Collection `#{opts}` is not an attribute"
Expand All @@ -307,26 +290,45 @@ def add_aggregate(attribute,aggregate,value)
def save(*opts)

if self.kind_of?(Goo::Base::Enum)
unless opts[0] && opts[0][:init_enum]
raise ArgumentError, "Enums can only be created on initialization"
end
raise ArgumentError, "Enums can only be created on initialization" unless opts[0] && opts[0][:init_enum]
end
batch_file = nil
if opts && opts.length > 0
if opts.first.is_a?(Hash) && opts.first[:batch] && opts.first[:batch].is_a?(File)
callbacks = true
if opts && opts.length > 0 && opts.first.is_a?(Hash)
if opts.first[:batch] && opts.first[:batch].is_a?(File)
batch_file = opts.first[:batch]
end

callbacks = opts.first[:callbacks]
end

if !batch_file
if not modified?
return self
end
return self if not modified?
raise Goo::Base::NotValidException, "Object is not valid. Check errors." unless valid?
end

#set default values before saving
unless self.persistent?
self.class.attributes_with_defaults.each do |attr|
value = self.send("#{attr}")
if value.nil?
value = self.class.default(attr).call(self)
self.send("#{attr}=", value)
end
end
end

#call update callback before saving
if callbacks
self.class.attributes_with_update_callbacks.each do |attr|
Goo::Validators::Enforce.enforce_callbacks(self, attr)
end
end

graph_insert, graph_delete = Goo::SPARQL::Triples.model_update_triples(self)
graph = self.graph()
graph = self.graph


if graph_delete and graph_delete.size > 0
begin
Goo.sparql_update_client.delete_data(graph_delete, graph: graph)
Expand Down Expand Up @@ -360,9 +362,7 @@ def save(*opts)

@modified_attributes = Set.new
@persistent = true
if self.class.inmutable? && self.class.inm_instances
self.class.load_inmutable_instances
end
self.class.load_inmutable_instances if self.class.inmutable? && self.class.inm_instances
return self
end

Expand Down Expand Up @@ -400,9 +400,7 @@ def to_hash
end
end
@unmapped.each do |attr,values|
unless all_attr_uris.include?(attr)
attr_hash[attr] = values.map { |v| v.to_s }
end
attr_hash[attr] = values.map { |v| v.to_s } unless all_attr_uris.include?(attr)
end
end
attr_hash[:id] = @id
Expand Down
Loading

0 comments on commit f943ac3

Please sign in to comment.