ldpath 1.1.0 → 1.2.0

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
- SHA1:
3
- metadata.gz: 2392ccdedd0caa14ab3a6a9be74043156d66cda1
4
- data.tar.gz: 25c171de64758510a076c32ee3fce37434707deb
2
+ SHA256:
3
+ metadata.gz: 82871915420d36fcd416a717f35185c1c1ab830390a65b071ea3740301d066b1
4
+ data.tar.gz: 41ecdc3227ddbf93b00dfe7929a4efaae21a31188a87fab19695958e3d946bfa
5
5
  SHA512:
6
- metadata.gz: 7fb33a6e0fe7af743f164ea41cee703c8a36f95ea216258297afd256b62e90da5d0b82c8c3aaf98eac4892118d6665abd647d68ff2f471874eb57cb108b0b924
7
- data.tar.gz: 9b2f191ee2bdf62d775d3110d07752914a00b4b4aa48d9886b16d6d84acd6c702e25367760f61a87b5776b7d1766ee9446334e4a871d82b8ddddab995e2a52a3
6
+ metadata.gz: 5b924bc7118ed584e4b0cf140ee51655b969a0ea7c0740ad17aae8732204833b6588971518e1db7e96ed6702f460098caa1f0cf83f2e49ed393dd229b7c158cd
7
+ data.tar.gz: dc0452a7565fb8d26ae1c078cd756479d88b2008aaf5faf8a64e7e6b17e667de358ac8836efd1296feb4662bd4ae31574c05b322995d7d42768aa138ca180a1a
@@ -0,0 +1,49 @@
1
+ ---
2
+ version: 2.1
3
+ orbs:
4
+ samvera: samvera/circleci-orb@1.0
5
+
6
+ jobs:
7
+ bundle_and_test:
8
+ parameters:
9
+ ruby_version:
10
+ type: string
11
+ bundler_version:
12
+ type: string
13
+ default: 2.3.10
14
+
15
+ executor:
16
+ name: 'samvera/ruby'
17
+ ruby_version: << parameters.ruby_version >>
18
+
19
+ environment:
20
+ COVERAGE: true
21
+
22
+ working_directory: ~/ldpath
23
+
24
+ steps:
25
+ - samvera/cached_checkout
26
+
27
+ - run: 'sudo apt-get update'
28
+
29
+ - samvera/bundle:
30
+ ruby_version: << parameters.ruby_version >>
31
+ bundler_version: << parameters.bundler_version >>
32
+ cache_version: "2"
33
+
34
+ - samvera/rubocop
35
+
36
+ - samvera/parallel_rspec
37
+
38
+ workflows:
39
+ ci:
40
+ jobs:
41
+ - bundle_and_test:
42
+ name: "ruby3-1"
43
+ ruby_version: "3.1.2"
44
+ - bundle_and_test:
45
+ name: "ruby3-0"
46
+ ruby_version: "3.0.0"
47
+ - bundle_and_test:
48
+ name: "ruby2-7"
49
+ ruby_version: "2.7.5"
data/.rubocop.yml CHANGED
@@ -1,8 +1,47 @@
1
+ inherit_gem:
2
+ bixby: bixby_default.yml
3
+
1
4
  inherit_from:
2
5
  - .rubocop_todo.yml
3
6
 
4
- Metrics/LineLength:
7
+ Layout/LineLength:
5
8
  Max: 140
9
+ Exclude:
10
+ - 'lib/ldpath/parser.rb'
11
+
12
+ Metrics/AbcSize:
13
+ Exclude:
14
+ - 'lib/ldpath/selectors.rb'
15
+
16
+ Metrics/CyclomaticComplexity:
17
+ Exclude:
18
+ - 'lib/ldpath/selectors.rb'
19
+
20
+ Metrics/BlockLength:
21
+ Exclude:
22
+ - 'spec/ldpath_parser_spec.rb'
23
+ - 'spec/ldpath_program_spec.rb'
24
+ - 'spec/ldpath_transform_spec.rb'
25
+ - 'spec/lib/functions/list_spec.rb'
26
+
27
+ Metrics/ClassLength:
28
+ Exclude:
29
+ - 'lib/ldpath/parser.rb'
30
+ - 'lib/ldpath/transform.rb'
31
+
32
+ Metrics/MethodLength:
33
+ Exclude:
34
+ - 'lib/ldpath/field_mapping.rb'
35
+ - 'lib/ldpath/selectors.rb'
36
+ - 'lib/ldpath/transform.rb'
37
+
38
+ Metrics/ModuleLength:
39
+ Exclude:
40
+ - 'lib/ldpath/functions.rb'
41
+
42
+ Metrics/ParameterLists:
43
+ Exclude:
44
+ - 'lib/ldpath/functions.rb'
6
45
 
7
46
  Style/WordArray:
8
47
  Enabled: false
data/CONTRIBUTING.md CHANGED
@@ -22,6 +22,28 @@ https://wiki.duraspace.org/display/samvera/Samvera+Community+Intellectual+Proper
22
22
 
23
23
  You should also add yourself to the `CONTRIBUTORS.md` file in the root of the project.
24
24
 
25
+ ## Language
26
+
27
+ The language we use matters. Today, tomorrow, and for years to come
28
+ people will read the code we write. They will judge us for our
29
+ design, logic, and the words we use to describe the system.
30
+
31
+ Our words should be accessible. Favor descriptive words that give
32
+ meaning while avoiding reinforcing systemic inequities. For example,
33
+ in the Samvera community, we should favor using allowed\_list instead
34
+ of whitelist, denied\_list instead of blacklist, or source/copy
35
+ instead of master/slave.
36
+
37
+ We're going to get it wrong, but this is a call to keep working to
38
+ make it right. View our code and the words we choose as a chance to
39
+ have a conversation. A chance to grow an understanding of the systems
40
+ we develop as well as the systems in which we live.
41
+
42
+ See [“Blacklists” and “whitelists”: a salutary warning concerning the
43
+ prevalence of racist language in discussions of predatory
44
+ publishing](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6148600/) for
45
+ further details.
46
+
25
47
  ## Contribution Tasks
26
48
 
27
49
  * Reporting Issues
@@ -34,7 +56,7 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
34
56
  ### Reporting Issues
35
57
 
36
58
  * Make sure you have a [GitHub account](https://github.com/signup/free)
37
- * Submit a [Github issue](https://github.com/samvera/questioning_authority/issues) by:
59
+ * Submit a [Github issue](https://github.com/samvera-labs/ldpath/issues) by:
38
60
  * Clearly describing the issue
39
61
  * Provide a descriptive summary
40
62
  * Explain the expected behavior
@@ -45,15 +67,22 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
45
67
 
46
68
  * Fork the repository on GitHub
47
69
  * Create a topic branch from where you want to base your work.
48
- * This is usually the master branch.
49
- * To quickly create a topic branch based on master; `git branch fix/master/my_contribution master`
50
- * Then checkout the new branch with `git checkout fix/master/my_contribution`.
51
- * Please avoid working directly on the `master` branch.
70
+ * This is usually the `main` branch.
71
+ * To quickly create a topic branch based on `main`; `git branch fix/main/my_contribution main`
72
+ * Then checkout the new branch with `git checkout fix/main/my_contribution`.
73
+ * Please avoid working directly on the `main` branch.
74
+ * Please do not create a branch called `master`. (See note below.)
52
75
  * You may find the [hub suite of commands](https://github.com/defunkt/hub) helpful
53
76
  * Make sure you have added sufficient tests and documentation for your changes.
54
77
  * Test functionality with RSpec; Test features / UI with Capybara.
55
78
  * Run _all_ the tests to assure nothing else was accidentally broken.
56
79
 
80
+ NOTE: This repository follows the [Samvera Community Code of Conduct](https://samvera.atlassian.net/wiki/spaces/samvera/pages/405212316/Code+of+Conduct)
81
+ and [language recommendations](#language).
82
+ Please ***do not*** create a branch called `master` for this repository or as part of
83
+ your pull request; the branch will either need to be removed or renamed before it can
84
+ be considered for inclusion in the code base and history of this repository.
85
+
57
86
  ### Documenting Code
58
87
 
59
88
  * All new public methods, modules, and classes should include inline documentation in [YARD](http://yardoc.org/).
@@ -109,15 +138,15 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
109
138
  ### Submitting Changes
110
139
 
111
140
  * Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
112
- * Make sure your branch is up to date with its parent branch (i.e. master)
113
- * `git checkout master`
141
+ * Make sure your branch is up to date with its parent branch (i.e. main)
142
+ * `git checkout main`
114
143
  * `git pull --rebase`
115
144
  * `git checkout <your-branch>`
116
- * `git rebase master`
145
+ * `git rebase main`
117
146
  * It is a good idea to run your tests again.
118
147
  * If you've made more than one commit take a moment to consider whether squashing commits together would help improve their logical grouping.
119
148
  * [Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)
120
- * `git rebase --interactive master` ([See Github help](https://help.github.com/articles/interactive-rebase))
149
+ * `git rebase --interactive main` ([See Github help](https://help.github.com/articles/interactive-rebase))
121
150
  * Squashing your branch's changes into one commit is "good form" and helps the person merging your request to see everything that is going on.
122
151
  * Push your changes to a topic branch in your fork of the repository.
123
152
  * Submit a pull request from your fork to the project.
@@ -127,12 +156,15 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
127
156
  We adopted [Github's Pull Request Review](https://help.github.com/articles/about-pull-request-reviews/) for our repositories.
128
157
  Common checks that may occur in our repositories:
129
158
 
130
- 1. Travis CI - where our automated tests are running
131
- 2. Approval Required - Github enforces at least one person approve a pull request. Also, all reviewers that have chimed in must approve.
159
+ 1. [CircleCI](https://circleci.com/gh/samvera) - where our automated tests are running
160
+ 2. RuboCop/Bixby - where we check for style violations
161
+ 3. Approval Required - Github enforces at least one person approve a pull request. Also, all reviewers that have chimed in must approve.
162
+ 4. CodeClimate - is our code remaining healthy (at least according to static code analysis)
163
+
132
164
 
133
165
  If one or more of the required checks failed (or are incomplete), the code should not be merged (and the UI will not allow it). If all of the checks have passed, then anyone on the project (including the pull request submitter) may merge the code.
134
166
 
135
- *Example: Carolyn submits a pull request, Justin reviews the pull request and approves. However, Justin is still waiting on other checks (Travis CI is usually the culprit), so he does not merge the pull request. Eventually, all of the checks pass. At this point, Carolyn or anyone else may merge the pull request.*
167
+ *Example: Carolyn submits a pull request, Justin reviews the pull request and approves. However, Justin is still waiting on other checks (CI tests are usually the culprit), so he does not merge the pull request. Eventually, all of the checks pass. At this point, Carolyn or anyone else may merge the pull request.*
136
168
 
137
169
  #### Things to Consider When Reviewing
138
170
 
@@ -149,7 +181,7 @@ This is your chance for a mentoring moment of another developer. Take time to gi
149
181
  * Do new or changed methods, modules, and classes have documentation?
150
182
  * Does the commit contain more than it should? Are two separate concerns being addressed in one commit?
151
183
  * Does the description of the new/changed specs match your understanding of what the spec is doing?
152
- * Did the Travis tests complete successfully?
184
+ * Did the Continuous Integration tests complete successfully?
153
185
 
154
186
  If you are uncertain, bring other contributors into the conversation by assigning them as a reviewer.
155
187
 
data/Gemfile CHANGED
@@ -1,8 +1,5 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
2
 
3
- gemspec path: File.expand_path('..', __FILE__)
3
+ source 'https://rubygems.org'
4
4
 
5
- group :development, :test do
6
- gem 'coveralls', require: false
7
- gem 'simplecov', require: false
8
- end
5
+ gemspec path: File.expand_path(__dir__)
data/README.md CHANGED
@@ -3,8 +3,7 @@
3
3
  This is a ruby implementation of [LDPath](http://marmotta.apache.org/ldpath/language.html), a language for selecting values linked data resources.
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/ldpath.png)](http://badge.fury.io/rb/ldpath)
6
- [![Build Status](https://travis-ci.org/samvera-labs/ldpath.png?branch=master)](https://travis-ci.org/samvera-labs/ldpath)
7
- [![Coverage Status](https://coveralls.io/repos/github/samvera-labs/ldpath/badge.svg?branch=master)](https://coveralls.io/github/samvera-labs/ldpath?branch=master)
6
+ [![Build Status](https://circleci.com/gh/samvera-labs/ldpath.svg?style=svg)]
8
7
 
9
8
  ## Installation
10
9
 
@@ -49,6 +48,12 @@ output = program.evaluate uri, context: context
49
48
 
50
49
  * Ruby 2.5 or the latest 2.4 version is recommended. Later versions may also work.
51
50
 
51
+ ## Contributing
52
+
53
+ If you're working on PR for this project, create a feature branch off of `main`.
54
+
55
+ This repository follows the [Samvera Community Code of Conduct](https://samvera.atlassian.net/wiki/spaces/samvera/pages/405212316/Code+of+Conduct) and [language recommendations](https://github.com/samvera/maintenance/blob/master/templates/CONTRIBUTING.md#language). Please ***do not*** create a branch called `master` for this repository or as part of your pull request; the branch will either need to be removed or renamed before it can be considered for inclusion in the code base and history of this repository.
56
+
52
57
  ## Product Owner & Maintenance
53
58
 
54
59
  LDPath is moving toward being a Core Component of the Samvera community. The documentation for
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
data/bin/ldpath CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'optparse'
4
5
  require 'open-uri'
@@ -6,8 +7,10 @@ require 'ldpath'
6
7
 
7
8
  begin
8
9
  require 'rest-client'
10
+ # rubocop:disable Lint/SuppressedException
9
11
  rescue LoadError
10
12
  end
13
+ # rubocop:enable Lint/SuppressedException
11
14
 
12
15
  options = {}
13
16
  opt_parser = OptionParser.new do |opts|
@@ -15,7 +18,9 @@ opt_parser = OptionParser.new do |opts|
15
18
 
16
19
  opts.on("--program=STRING_URI_OR_FILE", "LDPath program to run (reads from STDIN by default)") do |program|
17
20
  options[:program] = if File.exist?(program) || program =~ /^http/
21
+ # rubocop:disable Security/Open
18
22
  open(program).read
23
+ # rubocop:enable Security/Open
19
24
  elsif program.strip == "-"
20
25
  $stdin.read
21
26
  else
@@ -29,7 +34,7 @@ opt_parser.parse!
29
34
  uri = ARGV.shift
30
35
 
31
36
  if uri.nil?
32
- $stderr.puts opt_parser
37
+ warn opt_parser
33
38
  raise OptionParser::MissingArgument, "URI" unless uri
34
39
  end
35
40
 
data/ldpath.gemspec CHANGED
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'ldpath/version'
5
6
 
@@ -16,18 +17,19 @@ Gem::Specification.new do |spec|
16
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
19
  spec.require_paths = ["lib"]
20
+ spec.required_ruby_version = ">= 2.7.5"
19
21
 
22
+ spec.add_dependency "nokogiri", "~> 1.8"
20
23
  spec.add_dependency "parslet"
21
24
  spec.add_dependency "rdf", '~> 3.0'
22
- spec.add_dependency "nokogiri", "~> 1.8"
25
+ spec.add_dependency 'rdf-vocab', '~> 3.0'
23
26
 
24
- # spec.add_development_dependency "bixby", "~> 1.0.0"
25
- spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency "bixby", "~> 5.0"
26
28
  spec.add_development_dependency "byebug"
27
29
  spec.add_development_dependency "rake"
28
- spec.add_development_dependency "rspec"
29
30
  spec.add_development_dependency "rdf-reasoner"
30
- spec.add_development_dependency "simplecov"
31
- spec.add_development_dependency "rubocop"
31
+ spec.add_development_dependency "rspec"
32
+ spec.add_development_dependency 'rspec_junit_formatter'
33
+ spec.add_development_dependency "rubocop-rake"
32
34
  spec.add_development_dependency "webmock"
33
35
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Ldpath
2
4
  class FieldMapping
3
5
  attr_reader :name, :selector, :field_type
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # rubocop:disable Style/MethodName
2
4
  module Ldpath
3
5
  module Functions
@@ -60,13 +62,11 @@ module Ldpath
60
62
  end
61
63
 
62
64
  # collections
63
- def flatten(uri, context, lists)
65
+ def flatten(uri, context, lists, &block)
64
66
  return to_enum(:flatten, uri, context, lists) unless block_given?
65
67
 
66
68
  deep_flatten_compact(lists).each do |x|
67
- RDF::List.new(subject: x, graph: context).to_a.each do |i|
68
- yield i
69
- end
69
+ RDF::List.new(subject: x, graph: context).to_a.each(&block)
70
70
  end
71
71
  end
72
72
 
@@ -1,11 +1,17 @@
1
- class Ldpath::Loaders::Direct
2
- def load(uri)
3
- Ldpath.logger.debug "Loading #{uri.inspect}"
1
+ # frozen_string_literal: true
4
2
 
5
- reader_types = RDF::Format.reader_types.reject { |t| t.to_s =~ /html/ }.map do |t|
6
- t.to_s =~ %r{text/(?:plain|html)} ? "#{t};q=0.5" : t
7
- end
3
+ module Ldpath
4
+ module Loaders
5
+ class Direct
6
+ def load(uri)
7
+ Ldpath.logger.debug "Loading #{uri.inspect}"
8
+
9
+ reader_types = RDF::Format.reader_types.reject { |t| t.to_s =~ /html/ }.map do |t|
10
+ %r{text/(?:plain|html)}.match?(t.to_s) ? "#{t};q=0.5" : t
11
+ end
8
12
 
9
- RDF::Graph.load(uri, headers: { 'Accept' => reader_types.join(", ") })
13
+ RDF::Graph.load(uri, headers: { 'Accept' => reader_types.join(", ") })
14
+ end
15
+ end
10
16
  end
11
17
  end
@@ -1,9 +1,15 @@
1
- class Ldpath::Loaders::Graph
2
- def initialize(graph:)
3
- @graph = graph
4
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Ldpath
4
+ module Loaders
5
+ class Graph
6
+ def initialize(graph:)
7
+ @graph = graph
8
+ end
5
9
 
6
- def load(uri)
7
- @graph
10
+ def load(_uri)
11
+ @graph
12
+ end
13
+ end
8
14
  end
9
15
  end
@@ -1,25 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cgi'
2
4
 
3
- class Ldpath::Loaders::LinkedDataFragment
4
- NEXT_PAGE = RDF::URI('http://www.w3.org/ns/hydra/core#nextPage')
5
+ module Ldpath
6
+ module Loaders
7
+ class LinkedDataFragment
8
+ NEXT_PAGE = RDF::URI('http://www.w3.org/ns/hydra/core#nextPage')
5
9
 
6
- def initialize(endpoint)
7
- @endpoint = endpoint
8
- end
10
+ def initialize(endpoint)
11
+ @endpoint = endpoint
12
+ end
9
13
 
10
- def load(uri)
11
- Ldpath.logger.debug "Loading LDF data for #{uri.inspect}"
14
+ def load(uri)
15
+ Ldpath.logger.debug "Loading LDF data for #{uri.inspect}"
12
16
 
13
- graph = RDF::Graph.new
14
- request_uri = RDF::URI("#{@endpoint}?subject=#{CGI::escape(uri)}")
17
+ graph = RDF::Graph.new
18
+ request_uri = RDF::URI("#{@endpoint}?subject=#{CGI.escape(uri)}")
15
19
 
16
- while request_uri
17
- Ldpath.logger.debug " -- querying #{request_uri}"
18
- request_graph = RDF::Graph.load(request_uri)
19
- graph.insert_statements(request_graph)
20
- request_uri = request_graph.first_object([request_uri, NEXT_PAGE, nil])
21
- end
20
+ while request_uri
21
+ Ldpath.logger.debug " -- querying #{request_uri}"
22
+ request_graph = RDF::Graph.load(request_uri)
23
+ graph.insert_statements(request_graph)
24
+ request_uri = request_graph.first_object([request_uri, NEXT_PAGE, nil])
25
+ end
22
26
 
23
- graph
27
+ graph
28
+ end
29
+ end
24
30
  end
25
31
  end
@@ -1,5 +1,9 @@
1
- class Ldpath::Loaders
2
- require 'ldpath/loaders/direct'
3
- require 'ldpath/loaders/graph'
4
- require 'ldpath/loaders/linked_data_fragment'
1
+ # frozen_string_literal: true
2
+
3
+ module Ldpath
4
+ module Loaders
5
+ autoload(:Direct, 'ldpath/loaders/direct')
6
+ autoload(:Graph, 'ldpath/loaders/graph')
7
+ autoload(:LinkedDataFragment, 'ldpath/loaders/linked_data_fragment')
8
+ end
5
9
  end
data/lib/ldpath/parser.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'parslet'
2
4
 
3
5
  module Ldpath
@@ -39,7 +41,7 @@ module Ldpath
39
41
 
40
42
  rule(:exponent) { match('[Ee]') >> match("[+-]").maybe >> match("\\d").repeat(1) }
41
43
  rule(:numeric_literal) { integer.as(:integer) | decimal.as(:decimal) | double.as(:double) }
42
- rule(:boolean_literal) { str('true').as(:true) | str('false').as(:false) }
44
+ rule(:boolean_literal) { str('true').as(true) | str('false').as(false) }
43
45
 
44
46
  rule(:string) { string_literal_quote | string_literal_single_quote | string_literal_long_single_quote | string_literal_long_quote }
45
47
 
@@ -150,7 +152,7 @@ module Ldpath
150
152
  (identifier | str("")).as(:id) >> wsp? >>
151
153
  colon >> wsp? >>
152
154
  iriref >> space? >> scolon.maybe
153
- ).as(:prefixID)
155
+ ).as(:prefixID)
154
156
  end
155
157
 
156
158
  # @graph iri, iri, iri ;
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Ldpath
2
4
  class Program
3
5
  ParseError = Class.new StandardError
@@ -6,7 +8,7 @@ module Ldpath
6
8
  def parse(program, transform_context = {})
7
9
  ast = transform.apply load(program), transform_context
8
10
 
9
- Ldpath::Program.new ast.compact, transform_context
11
+ Ldpath::Program.new ast.compact, **transform_context
10
12
  end
11
13
 
12
14
  def load(program)
@@ -27,26 +29,24 @@ module Ldpath
27
29
  end
28
30
 
29
31
  attr_reader :mappings, :prefixes, :filters, :default_loader, :loaders
32
+
30
33
  def initialize(mappings, default_loader: Ldpath::Loaders::Direct.new, prefixes: {}, filters: [], loaders: {})
31
- @mappings ||= mappings
34
+ @mappings = mappings
32
35
  @default_loader = default_loader
33
36
  @loaders = loaders
34
37
  @prefixes = prefixes
35
38
  @filters = filters
36
-
37
39
  end
38
40
 
39
41
  def evaluate(uri, context: nil, limit_to_context: false)
40
42
  result = Ldpath::Result.new(self, uri, context: context, limit_to_context: limit_to_context)
41
- unless filters.empty?
42
- return {} unless filters.all? { |f| f.evaluate(result, uri, result.context) }
43
- end
43
+ return {} if !filters.empty? && !filters.all? { |f| f.evaluate(result, uri, result.context) }
44
44
 
45
45
  result.to_hash
46
46
  end
47
47
 
48
48
  def load(uri)
49
- loader = loaders.find { |k, v| uri =~ k }&.last
49
+ loader = loaders.find { |k, _v| uri =~ k }&.last
50
50
  loader ||= default_loader
51
51
 
52
52
  loader.load(uri)
data/lib/ldpath/result.rb CHANGED
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/module/delegation'
4
+
1
5
  module Ldpath
2
6
  class Result
3
7
  include Ldpath::Functions
@@ -13,7 +17,7 @@ module Ldpath
13
17
  end
14
18
 
15
19
  def loading(uri, context)
16
- return unless uri.to_s =~ /^http/
20
+ return unless /^http/.match?(uri.to_s)
17
21
  return if loaded[uri.to_s]
18
22
 
19
23
  context << load_graph(uri.to_s) unless limit_to_context?
@@ -21,9 +25,7 @@ module Ldpath
21
25
  end
22
26
 
23
27
  def load_graph(uri)
24
- cache[uri] ||= begin
25
- program.load(uri).tap { loaded[uri] = true }
26
- end
28
+ cache[uri] ||= program.load(uri).tap { loaded[uri] = true }
27
29
  end
28
30
 
29
31
  def [](key)
@@ -48,9 +50,7 @@ module Ldpath
48
50
  @context ||= load_graph(uri.to_s)
49
51
  end
50
52
 
51
- def prefixes
52
- program.prefixes
53
- end
53
+ delegate :prefixes, to: :program
54
54
 
55
55
  def meta
56
56
  @meta ||= {}