qa-ldf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rubocop.yml +21 -0
  4. data/.travis.yml +15 -0
  5. data/.yardopts +9 -0
  6. data/CONTRIBUTING.md +109 -0
  7. data/Gemfile +18 -0
  8. data/Guardfile +27 -0
  9. data/LICENSE +14 -0
  10. data/README.md +42 -0
  11. data/Rakefile +30 -0
  12. data/VERSION +1 -0
  13. data/config/ldf.yml +15 -0
  14. data/lib/qa/ldf.rb +43 -0
  15. data/lib/qa/ldf/authorities.rb +1 -0
  16. data/lib/qa/ldf/authorities/lc_names.rb +31 -0
  17. data/lib/qa/ldf/authority.rb +104 -0
  18. data/lib/qa/ldf/client.rb +39 -0
  19. data/lib/qa/ldf/configuration.rb +67 -0
  20. data/lib/qa/ldf/empty_search_service.rb +18 -0
  21. data/lib/qa/ldf/json_mapper.rb +35 -0
  22. data/lib/qa/ldf/model.rb +49 -0
  23. data/lib/qa/ldf/spec.rb +3 -0
  24. data/lib/qa/ldf/spec/authority.rb +112 -0
  25. data/lib/qa/ldf/spec/model.rb +9 -0
  26. data/lib/qa/ldf/spec/search_service.rb +30 -0
  27. data/lib/qa/ldf/version.rb +34 -0
  28. data/qa-ldf.gemspec +35 -0
  29. data/spec/contracts/qa_loc_as_search_service_spec.rb +38 -0
  30. data/spec/qa/ldf/authorities/lc_names_spec.rb +52 -0
  31. data/spec/qa/ldf/authority_spec.rb +29 -0
  32. data/spec/qa/ldf/client_spec.rb +23 -0
  33. data/spec/qa/ldf/configuration_spec.rb +93 -0
  34. data/spec/qa/ldf/empty_search_service_spec.rb +11 -0
  35. data/spec/qa/ldf/json_mapper_spec.rb +22 -0
  36. data/spec/qa/ldf/model_spec.rb +53 -0
  37. data/spec/qa/ldf_spec.rb +43 -0
  38. data/spec/spec_helper.rb +18 -0
  39. data/spec/support/cache_server.rb +25 -0
  40. data/spec/support/fake_client.rb +31 -0
  41. data/spec/support/fake_search_service.rb +40 -0
  42. data/spec/support/shared_examples/ld_cache_client.rb +35 -0
  43. metadata +232 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a949f884516d5b051b47a5b14d23c67043a0d3d3
4
+ data.tar.gz: 50ca4ecf8a10304ac8a2afa38afd38264c537ebe
5
+ SHA512:
6
+ metadata.gz: 5ef5befc68d69cf514995bdacaea034fdbb1c03b0c4effe9898f91cd57547ae26585414b40bc158171ae7bb3850ca06c42b5157dac15bd581b2ff106e5e59c22
7
+ data.tar.gz: 5a1d78db92bfc2de9d80b60292cb5dc0c1d3cc72bc210885529bcd56510ec6a455079e3a9d97df5538056d12cd6844a3d40245bba54bb4acabb10b05073a831e
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ # Ignore bundler config.
2
+ /.bundle
3
+
4
+ *~
5
+ *#
6
+
7
+ .yardoc
8
+ /doc
9
+
10
+ /log/*.log
11
+ /tmp
12
+ Gemfile.lock
13
+ coverage
14
+ pkg
15
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ DisplayCopNames: true
5
+
6
+ Metric/BlockLength:
7
+ Exclude:
8
+ - 'spec/**/*'
9
+ - 'lib/qa/ldf/spec/**/*'
10
+
11
+ # we accept `expect(subject).to receive`
12
+ RSpec/MessageSpies:
13
+ Enabled: false
14
+
15
+ # we accept specs in fakes, mocks, &c...
16
+ RSpec/FilePath:
17
+ Exclude:
18
+ - 'spec/contracts/**/*'
19
+ - 'spec/support/**/*'
20
+ - 'spec/qa/ldf/authorities/**/*'
21
+ - 'spec/qa/ldf/models/**/*'
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ sudo: false
3
+
4
+ cache:
5
+ bundler: true
6
+
7
+ rvm:
8
+ - 2.3.3
9
+ - 2.4.0
10
+
11
+ env:
12
+ global:
13
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
14
+ matrix:
15
+ - "RAILS_VERSION=5.0.0.1"
data/.yardopts ADDED
@@ -0,0 +1,9 @@
1
+ --title "Qa::LDF - Linked Data Caching for QuestioningAuthority"
2
+ --protected
3
+ --no-private
4
+ --hide-void-return
5
+ --markup markdown
6
+ --readme README.md
7
+ -
8
+ LICENSE
9
+ VERSION
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,109 @@
1
+ # How to Contribute
2
+
3
+ __We want your help to make Project Hydra great.__
4
+
5
+ There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
6
+
7
+ ## Hydra Project Intellectual Property Licensing and Ownership
8
+
9
+ All code contributors must have an Individual Contributor License Agreement (iCLA) on file with the Hydra Project Steering Group.
10
+ If the contributor works for an institution, the institution must have a Corporate Contributor License Agreement (cCLA) on file.
11
+
12
+ https://wiki.duraspace.org/display/hydra/Hydra+Project+Intellectual+Property+Licensing+and+Ownership
13
+
14
+ ## Contribution Tasks
15
+
16
+ * Reporting Issues
17
+ * Making Changes
18
+ * Submitting Changes
19
+ * Merging Changes
20
+
21
+ ### Reporting Issues
22
+
23
+ * Make sure you have a [GitHub account](https://github.com/signup/free)
24
+ * Submit a [Github issue](./issues) by:
25
+ * Clearly describing the issue
26
+ * Provide a descriptive summary
27
+ * Explain the expected behavior
28
+ * Explain the actual behavior
29
+ * Provide steps to reproduce the actual behavior
30
+
31
+ ### Making Changes
32
+
33
+ * Fork the repository on GitHub
34
+ * Create a topic branch from where you want to base your work.
35
+ * This will usually be based on the master branch.
36
+ * To quickly create a topic branch based on master; `git branch fix/master/my_contribution master`
37
+ * Then checkout the new branch with `git checkout fix/master/my_contribution`.
38
+ * Please avoid working directly on the `master` branch.
39
+ * You may find the [hub suite of commands](https://github.com/defunkt/hub) helpful.
40
+ * Make commits of logical units.
41
+ * Your commit should include a high level description of your work.
42
+ * Check for unnecessary whitespace with `git diff --check` before committing.
43
+ * Make sure your commit messages are [well formed](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
44
+ * If you created an issue, you can close it by including "Closes #issue" in your commit message. See [Github's blog post for more details](https://github.com/blog/1386-closing-issues-via-commit-messages)
45
+
46
+ ```
47
+ Present tense short summary (50 characters or less)
48
+
49
+ More detailed description, if necessary. It should be wrapped to 72
50
+ characters. Try to be as descriptive as you can, even if you think that
51
+ the commit content is obvious, it may not be obvious to others. You
52
+ should add such description also if it's already present in bug tracker,
53
+ it should not be necessary to visit a webpage to check the history.
54
+
55
+ Include Closes #<issue-number> when relavent.
56
+
57
+ Description can have multiple paragraphs and you can use code examples
58
+ inside, just indent it with 4 spaces:
59
+
60
+ class PostsController
61
+ def index
62
+ respond_with Post.limit(10)
63
+ end
64
+ end
65
+
66
+ You can also add bullet points:
67
+
68
+ - you can use dashes or asterisks for bullets.
69
+
70
+ - also, try to indent next line of a point for readability, if it's too
71
+ long to fit in 72 characters.
72
+ ```
73
+
74
+ * Make sure you have added the necessary tests for your changes.
75
+ * Run _all_ the tests to assure nothing else was accidentally broken.
76
+ * You can run all tests and style checks with `rake ci`.
77
+ * When you are ready, submit a pull request.
78
+
79
+ ### Submitting Changes
80
+
81
+ [Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)
82
+
83
+ * Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
84
+ * Make sure your branch is up to date with its parent branch (i.e. master)
85
+ * `git checkout master`
86
+ * `git pull --rebase`
87
+ * `git checkout <your-branch>`
88
+ * `git rebase master`
89
+ * It is likely a good idea to run your tests again.
90
+ * Push your changes to a topic branch in your fork of the repository.
91
+ * Submit a pull request from your fork to the project.
92
+
93
+ ### Merging Changes
94
+
95
+ * It is considered "poor from" to merge your own request.
96
+ * Please take the time to review the changes and get a sense of what is being changed. Things to consider:
97
+ * Does the commit message explain what is going on?
98
+ * Does the code changes have tests? _Not all changes need new tests, some changes are refactorings_.
99
+ * Does the commit contain more than it should? Are two separate concerns being addressed in one commit?
100
+ * Did the CI tests complete successfully?
101
+ * If you are uncertain, bring other contributors into the conversation by creating a comment that includes their @username.
102
+ * If you like the pull request, but want others to chime in, create a +1 comment and tag a user.
103
+
104
+ # Additional Resources
105
+
106
+ * [General GitHub documentation](http://help.github.com/)
107
+ * [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
108
+ * [Pro Git](http://git-scm.com/book) is both a free and excellent book about Git.
109
+ * [A Git Config for Contributing](http://ndlib.github.io/practices/my-typical-per-project-git-config/)
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ gemspec
5
+
6
+ git_source(:github) do |repo_name|
7
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
8
+ "https://github.com/#{repo_name}.git"
9
+ end
10
+
11
+ gem 'pry' unless ENV['CI']
12
+
13
+ # develop on qa master
14
+ gem 'qa', github: 'projecthydra-labs/questioning_authority', branch: 'master'
15
+
16
+ gem 'ld_cache_fragment',
17
+ github: 'ActiveTriples/linked-data-fragments',
18
+ branch: 'feature/multi-dataset'
data/Guardfile ADDED
@@ -0,0 +1,27 @@
1
+ # More info at https://github.com/guard/guard#readme
2
+
3
+ guard :rspec, cmd: 'bundle exec rspec' do
4
+ require 'guard/rspec/dsl'
5
+ dsl = Guard::RSpec::Dsl.new(self)
6
+
7
+ # Feel free to open issues for suggestions and improvements
8
+
9
+ # RSpec files
10
+ rspec = dsl.rspec
11
+ watch(rspec.spec_helper) { rspec.spec_dir }
12
+ watch(rspec.spec_support) { rspec.spec_dir }
13
+ watch(rspec.spec_files)
14
+
15
+ watch(%r{lib\/qa\/ldf\/spec\/.*\.rb}) { rspec.spec_dir }
16
+
17
+ # Ruby files
18
+ ruby = dsl.ruby
19
+ dsl.watch_spec_files_for(ruby.lib_files)
20
+ end
21
+
22
+ # Add files and commands to this file, like the example:
23
+ # watch(%r{file/path}) { `command(s)` }
24
+ #
25
+ guard :shell do
26
+ watch(/(.*).txt/) { |m| `tail #{m[0]}` }
27
+ end
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright 2017 Data Curation Experts LLC, Chemical Heritage Foundation
2
+ Additional copyright may be held by others, as reflected in the commit log
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ QuestioningAuthority::LDF
2
+ =========================
3
+ [![Apache 2.0 License](http://img.shields.io/badge/APACHE2-license-blue.svg)](./LICENSE)
4
+
5
+ Providies bindings from [Questioning Authority](https://github.com/projecthydra-labs/questioning_authority) to the [linked data caching fragment server](https://github.com/ActiveTriples/linked-data-fragments) for fast query of RDF-based authorities.
6
+
7
+ What Does This Do?
8
+ ------------------
9
+
10
+ Provides a caching version of the [Questioning Authority](https://github.com/projecthydra-labs/questioning_authority) interface relying on the ActiveTriples LDF caching service.
11
+
12
+ [TK] Why use this?
13
+
14
+ Upcoming features include:
15
+
16
+ - Support for `Qa::Authority::Base#all` for all LDF authorities through [Hydra Core Partial Collection View](http://www.hydra-cg.com/spec/latest/core/#hydra:PartialCollectionView) style paging.
17
+ - A default search, accessing cached items.
18
+
19
+ How Does it Work?
20
+ -----------------
21
+
22
+ ### [TK] Architecture Overview.
23
+ ### [TK] Mounting and configuring the LDF caching server.
24
+ ### [TK] LDF caching as an external service.
25
+ ### [TK] Configuring authorities.
26
+ #### [TK] Models.
27
+ #### [TK] Forms.
28
+
29
+ [TK] Authority Sources
30
+ ----------------------
31
+
32
+ ### [TK] LCNAF
33
+ ### [TK] FAST
34
+
35
+ [TK] Implementing Custom Authorities
36
+ ------------------------------------
37
+
38
+
39
+ License
40
+ -------
41
+
42
+ This software is available under {file:LICENSE the Apache 2.0 license}.
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env rake
2
+ require 'yard'
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
5
+
6
+ begin
7
+ require 'bundler/setup'
8
+ rescue LoadError
9
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
10
+ end
11
+
12
+ Bundler::GemHelper.install_tasks
13
+
14
+ desc 'Run style checker'
15
+ RuboCop::RakeTask.new(:rubocop) do |task|
16
+ task.fail_on_error = true
17
+ end
18
+
19
+ RSpec::Core::RakeTask.new(:spec)
20
+
21
+ desc 'Build YARD documentation'
22
+ YARD::Rake::YardocTask.new do |t|
23
+ t.files = ['lib/**/*.rb', 'LICENSE.md']
24
+ t.stats_options = ['--list-undoc']
25
+ end
26
+
27
+ desc 'Run continious integration'
28
+ task ci: [:rubocop, :spec]
29
+
30
+ task default: :ci
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/config/ldf.yml ADDED
@@ -0,0 +1,15 @@
1
+ development:
2
+ uri_endpoint: 'http://localhost:3000/{?subject}'
3
+ uri_root: 'http://localhost:3000/'
4
+ cache_backend:
5
+ provider: 'repository'
6
+ test: &TEST_
7
+ uri_endpoint: 'http://localhost:3000/{?subject}'
8
+ uri_root: 'http://localhost:3000/'
9
+ cache_backend:
10
+ provider: 'repository'
11
+ production:
12
+ uri_endpoint: 'http://localhost:3000/{?subject}'
13
+ uri_root: 'http://localhost:3000/'
14
+ cache_backend:
15
+ provider: 'repository'
data/lib/qa/ldf.rb ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ require 'qa/ldf/version'
3
+
4
+ require 'qa/ldf/configuration'
5
+ require 'qa/ldf/client'
6
+ require 'qa/ldf/json_mapper'
7
+ require 'qa/ldf/model'
8
+
9
+ require 'qa/ldf/authority'
10
+ require 'qa/ldf/authorities'
11
+
12
+ ##
13
+ # @see https://github.com/projecthydra-labs/questioning_authority Qa
14
+ module Qa
15
+ ##
16
+ # Provides bindings from `qa` to a linked data fragment caching service for
17
+ # fast query of RDF-based authorities.
18
+ #
19
+ # @see https://github.com/projecthydra-labs/questioning_authority Qa
20
+ # @see https://github.com/ActiveTriples/linked-data-fragments Linked Data
21
+ # Fragments Cache
22
+ module LDF
23
+ ##
24
+ # @return [Configuration] the singleton configuration instance
25
+ def self.config
26
+ @config ||= configure!
27
+ end
28
+
29
+ ##
30
+ # @example configuring with block syntax
31
+ # Qa::LDF.configure
32
+ # @see Configuration#configure
33
+ def self.configure!(**options, &block)
34
+ @config = Configuration.instance.configure!(**options, &block)
35
+ end
36
+
37
+ ##
38
+ # @see VERSION
39
+ def self.version
40
+ VERSION
41
+ end
42
+ end
43
+ end
@@ -0,0 +1 @@
1
+ require 'qa/ldf/authorities/lc_names'
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ module Qa
3
+ module LDF
4
+ ##
5
+ # A caching LCSH authority.
6
+ #
7
+ # @note This uses the search logic from the basic Loc authority that ships
8
+ # with QA: `Qa::Authorities::Loc::GenericAuthority`.
9
+ #
10
+ # @see LinkedDataFragments::CacheServer
11
+ class LCNames < Authority
12
+ DEFAULT_DATASET_NAME = :lcnames
13
+ LC_SUBAUTHORITY = 'names'.freeze
14
+
15
+ ##
16
+ # Uses the LC names subauthority as the search provider
17
+ def search_service
18
+ @search_service ||=
19
+ Qa::Authorities::Loc.subauthority_for(LC_SUBAUTHORITY)
20
+ end
21
+ end
22
+ end
23
+
24
+ ##
25
+ # Alias to hack Qa's namespaced authority logic.
26
+ #
27
+ # @see https://github.com/projecthydra-labs/questioning_authority/issues/137
28
+ module Authorities
29
+ Lcnames = LDF::LCNames
30
+ end
31
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+ require 'qa/authorities'
3
+ require 'qa/ldf/empty_search_service'
4
+
5
+ module Qa
6
+ module LDF
7
+ ##
8
+ # A Linked Data Fragments-based authority. Access linked data resources
9
+ # through a caching server.
10
+ #
11
+ # @see LinkedDataFragments::CacheServer
12
+ class Authority < Qa::Authorities::Base
13
+ ##
14
+ # The default linked data fragments client
15
+ DEFAULT_DATASET_NAME = :''
16
+
17
+ ##
18
+ # The default linked data fragments client
19
+ DEFAULT_CLIENT = Qa::LDF::Client
20
+
21
+ ##
22
+ # The default mapper
23
+ DEFAULT_MAPPER = Qa::LDF::JsonMapper
24
+
25
+ ##
26
+ # The default search service
27
+ DEFAULT_SEARCH_SERVICE = Qa::LDF::EmptySearchService
28
+
29
+ ##
30
+ # @!attribute [rw] client
31
+ # @return [Client]
32
+ # @!attribute [rw] dataset
33
+ # @return [Symbol] A dataset name (e.g. :lcsh)
34
+ # @!attribute [rw] mapper
35
+ # @return [Mapper]
36
+ # @!attribute [rw] search_service
37
+ # @return [#search]
38
+ attr_writer :client, :dataset, :mapper, :search_service
39
+
40
+ ##
41
+ # @yieldparam authority [Authority] self
42
+ def initialize(*)
43
+ super
44
+ yield self if block_given?
45
+ end
46
+
47
+ ##
48
+ # @see Qa::Authorities::Base#all
49
+ def all
50
+ []
51
+ end
52
+
53
+ ##
54
+ # Retrieves the given resource's JSON respresentation from the cache
55
+ # server.
56
+ #
57
+ # The resource is retrieved through the client given by `#client`, and
58
+ # mapped to JSON using `#mapper`.
59
+ #
60
+ # @see Qa::Authorities::Base#find
61
+ # @see Qa::LDF::Client#get
62
+ def find(id)
63
+ graph = client.get(uri: id, dataset: dataset)
64
+
65
+ mapper.map_resource(id, graph)
66
+ end
67
+
68
+ ##
69
+ # Search the vocabulary
70
+ #
71
+ # @param _query [String] the query string
72
+ #
73
+ # @return [Array<Hash<Symbol, String>>] the response as a JSON friendly
74
+ # hash
75
+ def search(query)
76
+ search_service.search(query)
77
+ end
78
+
79
+ ##
80
+ # @return [Qa::LDF::Client]
81
+ def client
82
+ @client ||= self.class::DEFAULT_CLIENT.new
83
+ end
84
+
85
+ ##
86
+ # @return [Symbol]
87
+ def dataset
88
+ @dataset ||= self.class::DEFAULT_DATASET_NAME
89
+ end
90
+
91
+ ##
92
+ # @return [JsonMapper]
93
+ def mapper
94
+ @mapper ||= self.class::DEFAULT_MAPPER.new
95
+ end
96
+
97
+ ##
98
+ # @return [#search]
99
+ def search_service
100
+ @search_service ||= self.class::DEFAULT_SEARCH_SERVICE.new
101
+ end
102
+ end
103
+ end
104
+ end