├── .gitignore
├── .rspec
├── .travis.yml
├── Gemfile
├── Guardfile
├── LICENSE
├── README.md
├── Rakefile
├── app
├── assets
│ ├── images
│ │ └── .keep
│ ├── javascripts
│ │ └── application.js
│ └── stylesheets
│ │ └── application.css
├── controllers
│ ├── application_controller.rb
│ ├── concerns
│ │ └── .keep
│ ├── dataset_controller.rb
│ └── subject_controller.rb
├── helpers
│ └── application_helper.rb
├── mailers
│ └── .keep
├── models
│ ├── .keep
│ └── setting.rb
└── views
│ └── layouts
│ └── application.html.erb
├── bin
├── bundle
├── rails
├── rake
├── setup
└── spring
├── circle.yml
├── config.ru
├── config
├── application.rb
├── boot.rb
├── database.yml
├── environment.rb
├── environments
│ ├── development.rb
│ ├── production.rb
│ └── test.rb
├── initializers
│ ├── assets.rb
│ ├── backtrace_silencers.rb
│ ├── cookies_serializer.rb
│ ├── filter_parameter_logging.rb
│ ├── inflections.rb
│ ├── mime_types.rb
│ ├── session_store.rb
│ └── wrap_parameters.rb
├── jetty.yml.sample
├── ldf.yml.sample_blazegraph
├── ldf.yml.sample_marmotta
├── ldf.yml.sample_repository
├── locales
│ └── en.yml
├── routes.rb
└── secrets.yml
├── db
└── seeds.rb
├── lib
├── assets
│ └── .keep
├── linked_data_fragments.rb
├── linked_data_fragments
│ ├── backend_base.rb
│ ├── blazegraph.rb
│ ├── builders.rb
│ ├── builders
│ │ ├── control_builder.rb
│ │ ├── dataset_builder.rb
│ │ └── template_builder.rb
│ ├── hydra_template.rb
│ ├── marmotta.rb
│ ├── models.rb
│ ├── models
│ │ ├── control.rb
│ │ ├── dataset.rb
│ │ ├── result.rb
│ │ └── template.rb
│ ├── repository.rb
│ ├── schemas.rb
│ ├── schemas
│ │ ├── control_schema.rb
│ │ ├── dataset_schema.rb
│ │ ├── result_schema.rb
│ │ └── template_schema.rb
│ ├── service.rb
│ └── settings.rb
└── tasks
│ └── .keep
├── log
└── .keep
├── public
├── 404.html
├── 422.html
├── 500.html
├── favicon.ico
└── robots.txt
├── spec
├── caching
│ ├── blazegraph_spec.rb
│ ├── marmotta_spec.rb
│ └── repository_spec.rb
├── cassettes
│ ├── LinkedDataFragments_Blazegraph
│ │ └── retrieve_a_subject_uri
│ │ │ ├── should_be_configured_as_a_Blazegraph_instance_with_the_mocked_uri.yml
│ │ │ └── should_retrieve_and_return_a_response_on_a_valid_subject_uri.yml
│ ├── LinkedDataFragments_Marmotta
│ │ └── retrieve_a_subject_uri
│ │ │ ├── should_be_configured_as_a_Marmotta_instance_with_the_mocked_uri.yml
│ │ │ ├── should_retrieve_and_return_a_response_on_a_valid_subject_uri.yml
│ │ │ └── should_retrieve_nothing_on_an_invalid_uri.yml
│ ├── LinkedDataFragments_Repository
│ │ ├── behaves_like_a_backend
│ │ │ ├── _add
│ │ │ │ └── adds_a_url.yml
│ │ │ ├── _delete_all_
│ │ │ │ ├── empties_backend.yml
│ │ │ │ └── removes_resources.yml
│ │ │ ├── _empty_
│ │ │ │ └── becomes_non-empty_when_a_resource_is_added.yml
│ │ │ ├── _has_
│ │ │ │ └── has_a_resource_that_has_been_added.yml
│ │ │ └── _retrieve
│ │ │ │ ├── when_empty
│ │ │ │ ├── loads_a_valid_URL.yml
│ │ │ │ └── raises_on_invalid_URL.yml
│ │ │ │ └── with_an_existing_resource
│ │ │ │ ├── gets_an_RDF_Enumerable.yml
│ │ │ │ └── raises_IOError_on_invalid_URL.yml
│ │ └── retrieve_a_subject_uri
│ │ │ ├── should_retrieve_and_return_a_response_on_a_valid_subject_uri.yml
│ │ │ └── should_retrieve_nothing_on_an_invalid_uri.yml
│ └── SubjectController
│ │ └── subject
│ │ └── JSON-LD
│ │ └── should_return_a_graph.yml
├── controllers
│ ├── dataset_controller_spec.rb
│ └── subject_controller_spec.rb
├── linked_data_fragments
│ ├── builders
│ │ ├── control_builder_spec.rb
│ │ ├── dataset_builder_spec.rb
│ │ └── template_builder_spec.rb
│ ├── hydra_template_spec.rb
│ ├── models
│ │ ├── control_spec.rb
│ │ ├── dataset_spec.rb
│ │ ├── result_spec.rb
│ │ └── template_spec.rb
│ ├── schemas
│ │ ├── control_schema_spec.rb
│ │ ├── dataset_schema_spec.rb
│ │ ├── result_schema_spec.rb
│ │ └── template_schema_spec.rb
│ ├── service_spec.rb
│ └── settings_spec.rb
├── rails_helper.rb
├── routing
│ ├── root_routing_spec.rb
│ └── subject_routing_spec.rb
├── spec_helper.rb
├── support
│ └── shared_examples
│ │ ├── backend.rb
│ │ └── schema.rb
└── vcr_setup.rb
└── vendor
└── assets
├── javascripts
└── .keep
└── stylesheets
└── .keep
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2 | #
3 | # If you find yourself ignoring temporary files generated by your text editor
4 | # or operating system, you probably want to add a global ignore instead:
5 | # git config --global core.excludesfile '~/.gitignore_global'
6 |
7 | # Ignore bundler config.
8 | /.bundle
9 |
10 | # Ignore the default SQLite database.
11 | /db/*.sqlite3
12 | /db/*.sqlite3-journal
13 |
14 | # Ignore all logfiles and tempfiles.
15 | /log/*
16 | !/log/.keep
17 | /tmp
18 |
19 | #Ignore the lock file so we can more easily all have different gems
20 | /Gemfile.lock
21 |
22 | #Ignore Rubymine and jetty files
23 | /.idea
24 | /jetty
25 | /ldf-jetty
26 |
27 | #Ignore yml files
28 | /*.yml
29 |
30 | # Ignore LDF config
31 | config/ldf.yml
32 |
--------------------------------------------------------------------------------
/.rspec:
--------------------------------------------------------------------------------
1 | --color
2 | --require spec_helper
3 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: ruby
2 | bundler_args: --without debug
3 | script: "bundle exec rake ci"
4 | sudo: false
5 | cache: bundler
6 | rvm:
7 | - 2.3.3
8 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 |
4 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
5 | gem 'rails', '4.2.1'
6 | # Use sqlite3 as the database for Active Record
7 | gem 'sqlite3'
8 | # Use SCSS for stylesheets
9 | gem 'sass-rails', '~> 5.0'
10 | # Use Uglifier as compressor for JavaScript assets
11 | gem 'uglifier', '>= 1.3.0'
12 | # Use CoffeeScript for .coffee assets and views
13 | gem 'coffee-rails', '~> 4.1.0'
14 | # See https://github.com/rails/execjs#readme for more supported runtimes
15 | # gem 'therubyracer', platforms: :ruby
16 |
17 | # Use jquery as the JavaScript library
18 | gem 'jquery-rails'
19 | # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
20 | gem 'turbolinks'
21 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
22 | gem 'jbuilder', '~> 2.0'
23 | # bundle exec rake doc:rails generates the API under doc/api.
24 | gem 'sdoc', '~> 0.4.0', group: :doc
25 |
26 | # Use ActiveModel has_secure_password
27 | # gem 'bcrypt', '~> 3.1.7'
28 |
29 | # Use Unicorn as the app server
30 | # gem 'unicorn'
31 |
32 | # Use Capistrano for deployment
33 | # gem 'capistrano-rails', group: :development
34 |
35 | gem 'responders'
36 | gem 'rdf'
37 | gem 'rdf-turtle'
38 | gem 'json-ld', '~> 1.99'
39 | #gem 'json-ld'
40 | gem 'active-triples'
41 | #gem 'rdf-vocab', github: "ruby-rdf/rdf-vocab", branch: "develop"
42 | gem 'rdf-vocab', '0.8.7.1'
43 | gem 'jettywrapper', '>= 2.0.0'
44 | gem 'marmotta'
45 | gem 'ldfwrapper', github: 'boston-library/ldf-wrapper', branch: "master"
46 | gem 'rdf-blazegraph'
47 |
48 | group :development, :test do
49 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console
50 | gem 'byebug'
51 |
52 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
53 | gem 'spring'
54 |
55 | gem 'rspec-rails'
56 | gem 'pry-byebug'
57 | end
58 |
59 | group :development do
60 | gem 'guard-rspec'
61 | # Access an IRB console on exception pages or by using <%= console %> in views
62 | gem 'web-console', '~> 2.0'
63 | end
64 |
65 | group :test do
66 | gem 'vcr'
67 | gem 'webmock'
68 | end
69 |
--------------------------------------------------------------------------------
/Guardfile:
--------------------------------------------------------------------------------
1 | # A sample Guardfile
2 | # More info at https://github.com/guard/guard#readme
3 |
4 | ## Uncomment and set this to only include directories you want to watch
5 | # directories %w(app lib config test spec features) \
6 | # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7 |
8 | ## Note: if you are using the `directories` clause above and you are not
9 | ## watching the project directory ('.'), then you will want to move
10 | ## the Guardfile to a watched dir and symlink it back, e.g.
11 | #
12 | # $ mkdir config
13 | # $ mv Guardfile config/
14 | # $ ln -s config/Guardfile .
15 | #
16 | # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17 |
18 | # Using -W0 to suppress warnings in automatic test runs
19 | guard :rspec, cmd: 'RUBYOPT="-W0" bundle exec rspec' do
20 | require 'guard/rspec/dsl'
21 | dsl = Guard::RSpec::Dsl.new(self)
22 |
23 | # Feel free to open issues for suggestions and improvements
24 |
25 | # RSpec files
26 | rspec = dsl.rspec
27 | watch(rspec.spec_helper) { rspec.spec_dir }
28 | watch(rspec.spec_support) { rspec.spec_dir }
29 | watch(rspec.spec_files)
30 |
31 | # Ruby files
32 | ruby = dsl.ruby
33 | dsl.watch_spec_files_for(ruby.lib_files)
34 | end
35 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | CC0 1.0 Universal
2 |
3 | Statement of Purpose
4 |
5 | The laws of most jurisdictions throughout the world automatically confer
6 | exclusive Copyright and Related Rights (defined below) upon the creator and
7 | subsequent owner(s) (each and all, an "owner") of an original work of
8 | authorship and/or a database (each, a "Work").
9 |
10 | Certain owners wish to permanently relinquish those rights to a Work for the
11 | purpose of contributing to a commons of creative, cultural and scientific
12 | works ("Commons") that the public can reliably and without fear of later
13 | claims of infringement build upon, modify, incorporate in other works, reuse
14 | and redistribute as freely as possible in any form whatsoever and for any
15 | purposes, including without limitation commercial purposes. These owners may
16 | contribute to the Commons to promote the ideal of a free culture and the
17 | further production of creative, cultural and scientific works, or to gain
18 | reputation or greater distribution for their Work in part through the use and
19 | efforts of others.
20 |
21 | For these and/or other purposes and motivations, and without any expectation
22 | of additional consideration or compensation, the person associating CC0 with a
23 | Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
24 | and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
25 | and publicly distribute the Work under its terms, with knowledge of his or her
26 | Copyright and Related Rights in the Work and the meaning and intended legal
27 | effect of CC0 on those rights.
28 |
29 | 1. Copyright and Related Rights. A Work made available under CC0 may be
30 | protected by copyright and related or neighboring rights ("Copyright and
31 | Related Rights"). Copyright and Related Rights include, but are not limited
32 | to, the following:
33 |
34 | i. the right to reproduce, adapt, distribute, perform, display, communicate,
35 | and translate a Work;
36 |
37 | ii. moral rights retained by the original author(s) and/or performer(s);
38 |
39 | iii. publicity and privacy rights pertaining to a person's image or likeness
40 | depicted in a Work;
41 |
42 | iv. rights protecting against unfair competition in regards to a Work,
43 | subject to the limitations in paragraph 4(a), below;
44 |
45 | v. rights protecting the extraction, dissemination, use and reuse of data in
46 | a Work;
47 |
48 | vi. database rights (such as those arising under Directive 96/9/EC of the
49 | European Parliament and of the Council of 11 March 1996 on the legal
50 | protection of databases, and under any national implementation thereof,
51 | including any amended or successor version of such directive); and
52 |
53 | vii. other similar, equivalent or corresponding rights throughout the world
54 | based on applicable law or treaty, and any national implementations thereof.
55 |
56 | 2. Waiver. To the greatest extent permitted by, but not in contravention of,
57 | applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
58 | unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
59 | and Related Rights and associated claims and causes of action, whether now
60 | known or unknown (including existing as well as future claims and causes of
61 | action), in the Work (i) in all territories worldwide, (ii) for the maximum
62 | duration provided by applicable law or treaty (including future time
63 | extensions), (iii) in any current or future medium and for any number of
64 | copies, and (iv) for any purpose whatsoever, including without limitation
65 | commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
66 | the Waiver for the benefit of each member of the public at large and to the
67 | detriment of Affirmer's heirs and successors, fully intending that such Waiver
68 | shall not be subject to revocation, rescission, cancellation, termination, or
69 | any other legal or equitable action to disrupt the quiet enjoyment of the Work
70 | by the public as contemplated by Affirmer's express Statement of Purpose.
71 |
72 | 3. Public License Fallback. Should any part of the Waiver for any reason be
73 | judged legally invalid or ineffective under applicable law, then the Waiver
74 | shall be preserved to the maximum extent permitted taking into account
75 | Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
76 | is so judged Affirmer hereby grants to each affected person a royalty-free,
77 | non transferable, non sublicensable, non exclusive, irrevocable and
78 | unconditional license to exercise Affirmer's Copyright and Related Rights in
79 | the Work (i) in all territories worldwide, (ii) for the maximum duration
80 | provided by applicable law or treaty (including future time extensions), (iii)
81 | in any current or future medium and for any number of copies, and (iv) for any
82 | purpose whatsoever, including without limitation commercial, advertising or
83 | promotional purposes (the "License"). The License shall be deemed effective as
84 | of the date CC0 was applied by Affirmer to the Work. Should any part of the
85 | License for any reason be judged legally invalid or ineffective under
86 | applicable law, such partial invalidity or ineffectiveness shall not
87 | invalidate the remainder of the License, and in such case Affirmer hereby
88 | affirms that he or she will not (i) exercise any of his or her remaining
89 | Copyright and Related Rights in the Work or (ii) assert any associated claims
90 | and causes of action with respect to the Work, in either case contrary to
91 | Affirmer's express Statement of Purpose.
92 |
93 | 4. Limitations and Disclaimers.
94 |
95 | a. No trademark or patent rights held by Affirmer are waived, abandoned,
96 | surrendered, licensed or otherwise affected by this document.
97 |
98 | b. Affirmer offers the Work as-is and makes no representations or warranties
99 | of any kind concerning the Work, express, implied, statutory or otherwise,
100 | including without limitation warranties of title, merchantability, fitness
101 | for a particular purpose, non infringement, or the absence of latent or
102 | other defects, accuracy, or the present or absence of errors, whether or not
103 | discoverable, all to the greatest extent permissible under applicable law.
104 |
105 | c. Affirmer disclaims responsibility for clearing rights of other persons
106 | that may apply to the Work or any use thereof, including without limitation
107 | any person's Copyright and Related Rights in the Work. Further, Affirmer
108 | disclaims responsibility for obtaining any necessary consents, permissions
109 | or other rights required for any use of the Work.
110 |
111 | d. Affirmer understands and acknowledges that Creative Commons is not a
112 | party to this document and has no duty or obligation with respect to this
113 | CC0 or use of the Work.
114 |
115 | For more information, please see
116 |
117 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Linked Data Fragments
2 | =====================
3 |
4 | A linked data fragment which takes an arbitrary subject and returns a cached
5 | result.
6 |
7 | Configuration
8 | =============
9 |
10 | YAML
11 | ----
12 |
13 | You need a ldf.yml file configured. There are currently two sample files for configurations of two different backend
14 | caching layers: ldf.yml.sample_marmotta and ldf.yml.sample_repository.
15 |
16 | Marmotta
17 | --------
18 |
19 | If you do not already have a marmotta instance, you can use an instance that runs off of jetty by running the following
20 | rake task:
21 |
22 | rake ldfjetty:install
23 |
24 | Once that finishes, please copy config/jetty.yml.sample to config/jetty.yml. You can change the defaults.
25 |
26 | Once that is all setup, here are some commands that can be run to use the marmotta instance:
27 |
28 | rake ldfjetty:stop
29 | rake ldfjetty:config
30 | rake ldfjetty:start
31 |
32 | Blazegraph
33 | -----------
34 |
35 | If you do not already have a blazegraph instance, you can use an instance that runs off of jetty by running the following
36 | rake task:
37 |
38 | rake ldfjetty:install
39 |
40 | Once that finishes, please copy config/ldfjetty.yml.sample to config/ldfjetty.yml. You can change the defaults.
41 |
42 | It is recommended that you populate Blazegraph with LoC for terms to work. To do this:
43 |
44 | * Download the latest subjects vocab from: [http://id.loc.gov/download/](http://id.loc.gov/download/) (the nt version of “LC Subject Headings (SKOS/RDF only)”)
45 |
46 | * Extract the above download into a directory.
47 |
48 | * Run the following command from that extraction directory:
49 | curl -H 'Content-Type: text/turtle' --upload-file subjects-skos-20140306.nt -X POST "http://localhost:8988/blazegraph/sparql?context-uri=http://id.loc.gov/static/data/authoritiessubjects.nt.skos.zip"
50 |
51 | Once that is all setup, here are some commands that can be run to use the blazegraph instance:
52 |
53 | rake ldfjetty:stop
54 | rake ldfjetty:config
55 | rake ldfjetty:start
56 |
57 | Usage
58 | =====
59 |
60 | Dataset Response
61 | ----------------
62 |
63 | In the default config, this is [http://localhost:3000?format=jsonld](http://localhost:3000?format=jsonld)
64 |
65 | Resolving a subject uri
66 | -----------------------
67 |
68 | In the default config, this would be something like [http://localhost:3000/http://dbpedia.org/resource/Berlin?format=jsonld](http://localhost:3000/http://dbpedia.org/resource/Berlin?format=jsonld)
69 | assuming that you have marmotta running and that linked data source configured in marmotta.
70 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require File.expand_path('../config/application', __FILE__)
5 |
6 | Rails.application.load_tasks
7 |
8 | desc 'Run CI'
9 | task :ci do
10 | sh 'cp config/ldf.yml.sample_repository config/ldf.yml'
11 | Rake::Task['spec'].invoke
12 | end
13 |
--------------------------------------------------------------------------------
/app/assets/images/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ActiveTriples/linked-data-fragments/a30e627cd079104a7e867c412f0e1cf77dcbf025/app/assets/images/.keep
--------------------------------------------------------------------------------
/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // compiled file.
9 | //
10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11 | // about supported directives.
12 | //
13 | //= require jquery
14 | //= require jquery_ujs
15 | //= require turbolinks
16 | //= require_tree .
17 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9 | * compiled file so the styles you add here take precedence over styles defined in any styles
10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11 | * file per style scope.
12 | *
13 | *= require_tree .
14 | *= require_self
15 | */
16 |
--------------------------------------------------------------------------------
/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | # Prevent CSRF attacks by raising an exception.
3 | # For APIs, you may want to use :null_session instead.
4 | protect_from_forgery with: :exception
5 |
6 | before_action :verify_format
7 |
8 | def verify_format
9 | if !renderer_mapping.keys.include?(request.format.symbol)
10 | raise ActionController::RoutingError.new("Invalid response format specified. Valid response formats are: #{renderer_mapping.keys.join(', ')} (#{renderer_mapping_to_strings.join(', ')}). Example url of how to set format: #{request.base_url}?format=jsonld")
11 | end
12 | end
13 |
14 |
15 | def self.renderer_mapping
16 | {
17 | :nt => lambda { |data| data.dump(:ntriples) },
18 | :jsonld => lambda { |data| data.dump(:jsonld, :standard_prefixes => true) },
19 | :ttl => lambda { |data| data.dump(:ttl) }
20 | }
21 | end
22 |
23 | def renderer_mapping
24 | self.class.renderer_mapping
25 | end
26 |
27 | def renderer_mapping_to_strings
28 | result = []
29 | renderer_mapping.each do |format, renderer|
30 | result.append(Mime::Type.lookup_by_extension(format).to_s)
31 | end
32 | return result
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ActiveTriples/linked-data-fragments/a30e627cd079104a7e867c412f0e1cf77dcbf025/app/controllers/concerns/.keep
--------------------------------------------------------------------------------
/app/controllers/dataset_controller.rb:
--------------------------------------------------------------------------------
1 | class DatasetController < ApplicationController
2 | def index
3 | @data = built_dataset
4 |
5 | respond_to do |f|
6 | renderer_mapping.each do |format, renderer|
7 | f.send(format) do
8 | render :text => renderer.call(@data)
9 | end
10 | end
11 | end
12 | end
13 |
14 | private
15 |
16 | def built_dataset
17 | LinkedDataFragments::DatasetBuilder.new.build
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/app/controllers/subject_controller.rb:
--------------------------------------------------------------------------------
1 | class SubjectController < ApplicationController
2 | before_action :fix_passed_params
3 |
4 | def self.cache_service
5 | LinkedDataFragments::Service.instance.cache
6 | end
7 |
8 | def subject
9 | data = self.class.cache_service.retrieve(params[:subject])
10 |
11 | respond_to do |f|
12 | renderer_mapping.each do |format, renderer|
13 | f.send(format) do
14 | render :text => renderer.call(data)
15 | end
16 | end
17 | end
18 | end
19 |
20 | private
21 |
22 | # Seems like a double '//' in the captured param is changed to a single one.
23 | # Unsure of how better to do this...
24 | def fix_passed_params
25 | single_slash_match = params[:subject].match(/^http[s]*\:\/(?!\/)/)
26 |
27 | if single_slash_match.present?
28 | params[:subject] =
29 | params[:subject][0..single_slash_match[0].length-1] + '/' +
30 | params[:subject][single_slash_match[0].length..params[:subject].length]
31 | end
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/mailers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ActiveTriples/linked-data-fragments/a30e627cd079104a7e867c412f0e1cf77dcbf025/app/mailers/.keep
--------------------------------------------------------------------------------
/app/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ActiveTriples/linked-data-fragments/a30e627cd079104a7e867c412f0e1cf77dcbf025/app/models/.keep
--------------------------------------------------------------------------------
/app/models/setting.rb:
--------------------------------------------------------------------------------
1 | ##
2 | # An alias to LinkedDataFragments::Settings
3 | Setting = LinkedDataFragments::Settings
4 |
--------------------------------------------------------------------------------
/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | LinkedDataFragments
5 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6 | <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7 | <%= csrf_meta_tags %>
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3 | load Gem.bin_path('bundler', 'bundle')
4 |
--------------------------------------------------------------------------------
/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path("../spring", __FILE__)
4 | rescue LoadError
5 | end
6 | APP_PATH = File.expand_path('../../config/application', __FILE__)
7 | require_relative '../config/boot'
8 | require 'rails/commands'
9 |
--------------------------------------------------------------------------------
/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path("../spring", __FILE__)
4 | rescue LoadError
5 | end
6 | require_relative '../config/boot'
7 | require 'rake'
8 | Rake.application.run
9 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'pathname'
3 |
4 | # path to your application root.
5 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6 |
7 | Dir.chdir APP_ROOT do
8 | # This script is a starting point to setup your application.
9 | # Add necessary setup steps to this file:
10 |
11 | puts "== Installing dependencies =="
12 | system "gem install bundler --conservative"
13 | system "bundle check || bundle install"
14 |
15 | # puts "\n== Copying sample files =="
16 | # unless File.exist?("config/database.yml")
17 | # system "cp config/database.yml.sample config/database.yml"
18 | # end
19 |
20 | puts "\n== Preparing database =="
21 | system "bin/rake db:setup"
22 |
23 | puts "\n== Removing old logs and tempfiles =="
24 | system "rm -f log/*"
25 | system "rm -rf tmp/cache"
26 |
27 | puts "\n== Restarting application server =="
28 | system "touch tmp/restart.txt"
29 | end
30 |
--------------------------------------------------------------------------------
/bin/spring:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # This file loads spring without using Bundler, in order to be fast.
4 | # It gets overwritten when you run the `spring binstub` command.
5 |
6 | unless defined?(Spring)
7 | require "rubygems"
8 | require "bundler"
9 |
10 | if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)
11 | Gem.paths = { "GEM_PATH" => [Bundler.bundle_path.to_s, *Gem.path].uniq }
12 | gem "spring", match[1]
13 | require "spring/binstub"
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/circle.yml:
--------------------------------------------------------------------------------
1 | machine:
2 | ruby:
3 | version: 2.2.0
4 | dependencies:
5 | post:
6 | - cp config/ldf.yml.sample_repository config/ldf.yml
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require ::File.expand_path('../config/environment', __FILE__)
4 | run Rails.application
5 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | require File.expand_path('../boot', __FILE__)
2 |
3 | require 'rails/all'
4 |
5 | # Require the gems listed in Gemfile, including any gems
6 | # you've limited to :test, :development, or :production.
7 | Bundler.require(*Rails.groups)
8 |
9 | module LinkedDataFragments
10 | class Application < Rails::Application
11 | config.autoload_paths += %W(#{config.root}/lib)
12 | # Settings in config/environments/* take precedence over those specified here.
13 | # Application configuration should go into files in config/initializers
14 | # -- all .rb files in that directory are automatically loaded.
15 |
16 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
17 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
18 | # config.time_zone = 'Central Time (US & Canada)'
19 |
20 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
21 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
22 | # config.i18n.default_locale = :de
23 |
24 | # Do not swallow errors in after_commit/after_rollback callbacks.
25 | config.active_record.raise_in_transactional_callbacks = true
26 | end
27 | end
28 |
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2 |
3 | require 'bundler/setup' # Set up gems listed in the Gemfile.
4 |
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | #
7 | default: &default
8 | adapter: sqlite3
9 | pool: 5
10 | timeout: 5000
11 |
12 | development:
13 | <<: *default
14 | database: db/development.sqlite3
15 |
16 | # Warning: The database defined as "test" will be erased and
17 | # re-generated from your development database when you run "rake".
18 | # Do not set this db to the same as development or production.
19 | test:
20 | <<: *default
21 | database: db/test.sqlite3
22 |
23 | production:
24 | <<: *default
25 | database: db/production.sqlite3
26 |
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require File.expand_path('../application', __FILE__)
3 |
4 | # Initialize the Rails application.
5 | Rails.application.initialize!
6 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the web server when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Do not eager load code on boot.
10 | config.eager_load = false
11 |
12 | # Show full error reports and disable caching.
13 | config.consider_all_requests_local = true
14 | config.action_controller.perform_caching = false
15 |
16 | # Don't care if the mailer can't send.
17 | config.action_mailer.raise_delivery_errors = false
18 |
19 | # Print deprecation notices to the Rails logger.
20 | config.active_support.deprecation = :log
21 |
22 | # Raise an error on page load if there are pending migrations.
23 | config.active_record.migration_error = :page_load
24 |
25 | # Debug mode disables concatenation and preprocessing of assets.
26 | # This option may cause significant delays in view rendering with a large
27 | # number of complex assets.
28 | config.assets.debug = true
29 |
30 | # Asset digests allow you to set far-future HTTP expiration dates on all assets,
31 | # yet still be able to expire them through the digest params.
32 | config.assets.digest = true
33 |
34 | # Adds additional error checking when serving assets at runtime.
35 | # Checks for improperly declared sprockets dependencies.
36 | # Raises helpful error messages.
37 | config.assets.raise_runtime_errors = true
38 |
39 | # Raises error for missing translations
40 | # config.action_view.raise_on_missing_translations = true
41 | end
42 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # Code is not reloaded between requests.
5 | config.cache_classes = true
6 |
7 | # Eager load code on boot. This eager loads most of Rails and
8 | # your application in memory, allowing both threaded web servers
9 | # and those relying on copy on write to perform better.
10 | # Rake tasks automatically ignore this option for performance.
11 | config.eager_load = true
12 |
13 | # Full error reports are disabled and caching is turned on.
14 | config.consider_all_requests_local = false
15 | config.action_controller.perform_caching = true
16 |
17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application
18 | # Add `rack-cache` to your Gemfile before enabling this.
19 | # For large-scale production use, consider using a caching reverse proxy like
20 | # NGINX, varnish or squid.
21 | # config.action_dispatch.rack_cache = true
22 |
23 | # Disable serving static files from the `/public` folder by default since
24 | # Apache or NGINX already handles this.
25 | config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
26 |
27 | # Compress JavaScripts and CSS.
28 | config.assets.js_compressor = :uglifier
29 | # config.assets.css_compressor = :sass
30 |
31 | # Do not fallback to assets pipeline if a precompiled asset is missed.
32 | config.assets.compile = false
33 |
34 | # Asset digests allow you to set far-future HTTP expiration dates on all assets,
35 | # yet still be able to expire them through the digest params.
36 | config.assets.digest = true
37 |
38 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
39 |
40 | # Specifies the header that your server uses for sending files.
41 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
42 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
43 |
44 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
45 | # config.force_ssl = true
46 |
47 | # Use the lowest log level to ensure availability of diagnostic information
48 | # when problems arise.
49 | config.log_level = :debug
50 |
51 | # Prepend all log lines with the following tags.
52 | # config.log_tags = [ :subdomain, :uuid ]
53 |
54 | # Use a different logger for distributed setups.
55 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
56 |
57 | # Use a different cache store in production.
58 | # config.cache_store = :mem_cache_store
59 |
60 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
61 | # config.action_controller.asset_host = 'http://assets.example.com'
62 |
63 | # Ignore bad email addresses and do not raise email delivery errors.
64 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
65 | # config.action_mailer.raise_delivery_errors = false
66 |
67 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
68 | # the I18n.default_locale when a translation cannot be found).
69 | config.i18n.fallbacks = true
70 |
71 | # Send deprecation notices to registered listeners.
72 | config.active_support.deprecation = :notify
73 |
74 | # Use default logging formatter so that PID and timestamp are not suppressed.
75 | config.log_formatter = ::Logger::Formatter.new
76 |
77 | # Do not dump schema after migrations.
78 | config.active_record.dump_schema_after_migration = false
79 | end
80 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Do not eager load code on boot. This avoids loading your whole application
11 | # just for the purpose of running a single test. If you are using a tool that
12 | # preloads Rails for running tests, you may have to set it to true.
13 | config.eager_load = false
14 |
15 | # Configure static file server for tests with Cache-Control for performance.
16 | config.serve_static_files = true
17 | config.static_cache_control = 'public, max-age=3600'
18 |
19 | # Show full error reports and disable caching.
20 | config.consider_all_requests_local = true
21 | config.action_controller.perform_caching = false
22 |
23 | # Raise exceptions instead of rendering exception templates.
24 | config.action_dispatch.show_exceptions = false
25 |
26 | # Disable request forgery protection in test environment.
27 | config.action_controller.allow_forgery_protection = false
28 |
29 | # Tell Action Mailer not to deliver emails to the real world.
30 | # The :test delivery method accumulates sent emails in the
31 | # ActionMailer::Base.deliveries array.
32 | config.action_mailer.delivery_method = :test
33 |
34 | # Randomize the order test cases are executed.
35 | config.active_support.test_order = :random
36 |
37 | # Print deprecation notices to the stderr.
38 | config.active_support.deprecation = :stderr
39 |
40 | # Raises error for missing translations
41 | # config.action_view.raise_on_missing_translations = true
42 | end
43 |
--------------------------------------------------------------------------------
/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = '1.0'
5 |
6 | # Add additional assets to the asset load path
7 | # Rails.application.config.assets.paths << Emoji.images_path
8 |
9 | # Precompile additional assets.
10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11 | # Rails.application.config.assets.precompile += %w( search.js )
12 |
--------------------------------------------------------------------------------
/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/config/initializers/cookies_serializer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.action_dispatch.cookies_serializer = :json
4 |
--------------------------------------------------------------------------------
/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure sensitive parameters which will be filtered from the log file.
4 | Rails.application.config.filter_parameters += [:password]
5 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, '\1en'
8 | # inflect.singular /^(ox)en/i, '\1'
9 | # inflect.irregular 'person', 'people'
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym 'RESTful'
16 | # end
17 |
--------------------------------------------------------------------------------
/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 | Mime::Type.register "application/ld+json", :jsonld
6 | Mime::Type.register "application/n-triples", :nt
7 | Mime::Type.register "text/turtle", :ttl
8 |
--------------------------------------------------------------------------------
/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.session_store :cookie_store, key: '_linked-data-fragments_session'
4 |
--------------------------------------------------------------------------------
/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9 | end
10 |
11 | # To enable root element in JSON for ActiveRecord objects.
12 | # ActiveSupport.on_load(:active_record) do
13 | # self.include_root_in_json = true
14 | # end
15 |
--------------------------------------------------------------------------------
/config/jetty.yml.sample:
--------------------------------------------------------------------------------
1 | development:
2 | startup_wait: 15
3 | jetty_port: 8983
4 | test: &TEST_
5 | startup_wait: 15
6 | jetty_port: 8983
7 | production:
8 | startup_wait: 15
9 | jetty_port: 8983
--------------------------------------------------------------------------------
/config/ldf.yml.sample_blazegraph:
--------------------------------------------------------------------------------
1 | development:
2 | uri_endpoint: 'http://localhost:3000/{?subject}'
3 | uri_root: 'http://localhost:3000/#dataset'
4 | cache_backend:
5 | provider: 'blazegraph'
6 | url: 'http://localhost:8988/blazegraph/sparql'
7 | context: 'http://localhost:8988/linked_data_fragments_dev'
8 | test: &TEST_
9 | uri_endpoint: 'http://localhost:3000/{?subject}'
10 | uri_root: 'http://localhost:3000/#dataset'
11 | cache_backend:
12 | provider: 'blazegraph'
13 | url: 'http://localhost:8988/blazegraph/sparql'
14 | context: 'http://localhost:8988/linked_data_fragments_test'
15 | production:
16 | uri_endpoint: 'http://localhost:3000/{?subject}'
17 | uri_root: 'http://localhost:3000/#dataset'
18 | cache_backend:
19 | provider: 'blazegraph'
20 | url: 'http://localhost:8988/blazegraph/sparql'
21 | context: 'http://localhost:8988/linked_data_fragments_production'
--------------------------------------------------------------------------------
/config/ldf.yml.sample_marmotta:
--------------------------------------------------------------------------------
1 | development:
2 | uri_endpoint: 'http://localhost:3000/{?subject}'
3 | uri_root: 'http://localhost:3000/#dataset'
4 | cache_backend:
5 | provider: 'marmotta'
6 | url: 'http://localhost:8988/marmotta'
7 | context: 'http://localhost:8988/linked_data_fragments_dev'
8 | test: &TEST_
9 | uri_endpoint: 'http://localhost:3000/{?subject}'
10 | uri_root: 'http://localhost:3000/#dataset'
11 | cache_backend:
12 | provider: 'marmotta'
13 | url: 'http://localhost:8988/marmotta'
14 | context: 'http://localhost:8988/linked_data_fragments_test'
15 | production:
16 | uri_endpoint: 'http://localhost:3000/{?subject}'
17 | uri_root: 'http://localhost:3000/#dataset'
18 | cache_backend:
19 | provider: 'marmotta'
20 | url: 'http://localhost:8988/marmotta'
21 | context: 'http://localhost:8988/linked_data_fragments_production'
--------------------------------------------------------------------------------
/config/ldf.yml.sample_repository:
--------------------------------------------------------------------------------
1 | development:
2 | uri_endpoint: 'http://localhost:3000/{?subject}'
3 | uri_root: 'http://localhost:3000/#dataset'
4 | cache_backend:
5 | provider: 'repository'
6 | test: &TEST_
7 | uri_endpoint: 'http://localhost:3000/{?subject}'
8 | uri_root: 'http://localhost:3000/#dataset'
9 | cache_backend:
10 | provider: 'repository'
11 | production:
12 | uri_endpoint: 'http://localhost:3000/{?subject}'
13 | uri_root: 'http://localhost:3000/#dataset'
14 | cache_backend:
15 | provider: 'repository'
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # To learn more, please read the Rails Internationalization guide
20 | # available at http://guides.rubyonrails.org/i18n.html.
21 |
22 | en:
23 | hello: "Hello world"
24 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 | root to: "dataset#index"
3 |
4 | get Setting.uri_endpoint_route, to: 'subject#subject', constraints: {
5 | :format => /(#{ApplicationController.renderer_mapping.keys.join("|")})/
6 | }
7 | end
8 |
--------------------------------------------------------------------------------
/config/secrets.yml:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key is used for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 |
6 | # Make sure the secret is at least 30 characters and all random,
7 | # no regular words or you'll be exposed to dictionary attacks.
8 | # You can use `rake secret` to generate a secure secret key.
9 |
10 | # Make sure the secrets in this file are kept private
11 | # if you're sharing your code publicly.
12 |
13 | development:
14 | secret_key_base: 4bef1126e50807c22fd2da7fa2000d9ee794f9126ee0f1ff5d1bc88747730765a5a3421fa1e4949c80a40bfd877b1d249be387300585509782b514ab37f34631
15 |
16 | test:
17 | secret_key_base: 2c06b6eca6cda33a0efe08a55a51ace327133c7f03e496eef569d4416a930ba43e6d9685002737f35684dd7b0196c5cab9c16b88584d3aa2a2f349a77d829d39
18 |
19 | # Do not keep production secrets in the repository,
20 | # instead read values from the environment.
21 | production:
22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
23 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7 | # Mayor.create(name: 'Emanuel', city: cities.first)
8 |
--------------------------------------------------------------------------------
/lib/assets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ActiveTriples/linked-data-fragments/a30e627cd079104a7e867c412f0e1cf77dcbf025/lib/assets/.keep
--------------------------------------------------------------------------------
/lib/linked_data_fragments.rb:
--------------------------------------------------------------------------------
1 | require 'active_triples'
2 |
3 | # must require 'rdf/vocab' first, due to const_missing metaprogramming in
4 | # pre-2.0 verisons
5 | require 'rdf/vocab'
6 | require 'rdf/vocab/hydra'
7 | require 'rdf/vocab/void'
8 |
9 | require 'linked_data_fragments/settings'
10 |
11 | require 'linked_data_fragments/builders'
12 | require 'linked_data_fragments/schemas'
13 | require 'linked_data_fragments/models'
14 | require 'linked_data_fragments/hydra_template'
15 |
16 | ##
17 | # A linked data caching fragment
18 | module LinkedDataFragments
19 | end
20 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/backend_base.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | ##
3 | # A base class for RDF backends.
4 | #
5 | # Several abstract methods are defined, which implementations must provide
6 | # concrete versions of.
7 | #
8 | # @note this interface provides no method for clearing (deleting) individual
9 | # resources from the cache.
10 | class BackendBase
11 | ##
12 | # A backend factory.
13 | #
14 | # @param name [#to_sym]
15 | # @return [BackendBase] a backend instance
16 | #
17 | # @raise [UnsupportedBackend] when the name does not match a repository
18 | def self.for(name: :repository)
19 | case name.to_sym
20 | when :marmotta
21 | LinkedDataFragments::Marmotta.new
22 | when :repository
23 | LinkedDataFragments::Repository.new
24 | when :blazegraph
25 | LinkedDataFragments::Blazegraph.new
26 | else
27 | raise UnsupportedBackend, "Invalid backend `#{name}` specified."
28 | end
29 | end
30 |
31 | ##
32 | # @!attribute [rw] cache_backend_url
33 | # @return [String, nil] a target url in string form; `nil` may be
34 | # returned when the backend repository is not remote.
35 | # @!attribute [rw] cache_backend_context
36 | # @return [String, nil] the context URI for the cache. When the backend
37 | # supports quads, statements will be stored in this context. `nil`
38 | # selects the default context.
39 | # @see https://www.w3.org/TR/rdf11-concepts/#section-dataset for
40 | # information about named graphs ("contexts") in the RDF abstract syntax
41 | # @see RDF::Dataset for documentation covering named graph support in
42 | # RDF.rb
43 | # @see RDF::Dataset#supports? for details about `:graph_name` support in
44 | # Repositories
45 | attr_accessor :cache_backend_url, :cache_backend_context
46 |
47 | ##
48 | # @abstract Add a resource to the backend. This method retrieves the
49 | # resource from its URI.
50 | #
51 | # @return [void]
52 | # @raise [IOError, Net::HTTPError] when retrieving the resource fails with
53 | # a non-2xx HTTP status code.
54 | # @see RDF::Graph#load this is typical implementation
55 | def add(uri)
56 | raise NotImplementedError,
57 | "#{self.class} should implement `#empty?`, but does not."
58 | end
59 |
60 | ##
61 | # @deprecated Use {#delete_all!} instead.
62 | # @return [void]
63 | def delete_all
64 | warn "[DEPRECATION] `#{self.class}#delete_all` is deprecated; " \
65 | "use `#{self.class}#delete_all! instead. Called from: " \
66 | "#{Gem.location_of_caller.join(':')}"
67 | delete_all!
68 | end
69 |
70 | ##
71 | # @abstract Implementations must remove all resources from the backend.
72 | #
73 | # @return [void]
74 | def delete_all!
75 | raise NotImplementedError,
76 | "#{self.class} should implement `#delete_all!`, but does not."
77 | end
78 |
79 | ##
80 | # @abstract
81 | # @return [Boolean] `true` if no resources are stored.
82 | def empty?
83 | raise NotImplementedError,
84 | "#{self.class} should implement `#empty?`, but does not."
85 | end
86 |
87 | ##
88 | # @deprecation This now just echos the argument. Callers should remove
89 | # sends to this method, and use the argument instead.
90 | # @param uri [String, RDF::URI] a URI or URI-like string
91 | # @return [String, RDF::URI] the mapped string
92 | def get_resource_uri(uri)
93 | warn '[DEPRECATION] #get_resource_uri echos its argument. Callers ' \
94 | 'should replace method calls with the argument, instead ' \
95 | "Called from: #{Gem.location_of_caller.join(':')}"
96 | uri
97 | end
98 |
99 | ##
100 | # @abstract checks whether the resource is in the cache
101 | #
102 | # @param uri [String, RDF::URI] a URI or URI-like string
103 | # @return [Boolean]
104 | def has_resource?(uri)
105 | raise NotImplementedError,
106 | "#{self.class} should implement `#has_resource?`, but does not."
107 | end
108 |
109 | ##
110 | # @abstract Retrieves RDF statements for a selected resource.
111 | #
112 | # @todo Should this simply implement the base verison against
113 | # `RDF::Repository`?
114 | # @todo What are we supposed to return if the resource does not exist?
115 | #
116 | # @param uri [String, RDF::URI] a URI or URI-like string
117 | # @return [RDF::Enumerable] the statements representing requested resource
118 | def retrieve(uri)
119 | raise NotImplementedError,
120 | "#{self.class} should implement `#retrieve!`, but does not."
121 | end
122 |
123 | class UnsupportedBackend < NameError; end
124 | end
125 | end
126 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/blazegraph.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | class Blazegraph < BackendBase
3 | def initialize
4 | #@repo ||= ::RDF::Blazegraph::Repository.new(uri: Setting.cache_backend_url, context: Setting.cache_backend_context)
5 | self.cache_backend_url = Setting.cache_backend_url
6 | self.cache_backend_context = Setting.cache_backend_context
7 | @repo ||= ::RDF::Blazegraph::Repository.new(Setting.cache_backend_url)
8 | end
9 |
10 | def retrieve(uri)
11 | @repo.load(uri) unless @repo.has_subject?(RDF::URI.new(uri))
12 |
13 | @repo.query(:subject => RDF::URI.new(uri))
14 | end
15 |
16 | def delete_all
17 | @repo.clear
18 | end
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/builders.rb:
--------------------------------------------------------------------------------
1 | require 'linked_data_fragments/builders/control_builder'
2 | require 'linked_data_fragments/builders/dataset_builder'
3 | require 'linked_data_fragments/builders/template_builder'
4 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/builders/control_builder.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | class ControlBuilder
3 | ##
4 | # @!attribute [rw] control
5 | # @return []
6 | # @!attribute [rw] property
7 | # @return [RDF::URI]
8 | attr_accessor :control, :property
9 |
10 | ##
11 | #
12 | def initialize(control, property)
13 | @control = control
14 | @property = property
15 | end
16 |
17 | ##
18 | # @return [Control]
19 | def build
20 | Control.new.tap do |t|
21 | t.variable = control
22 | t.property = property
23 | end
24 | end
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/builders/dataset_builder.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | ##
3 | # A Builder for Dataset instances.
4 | #
5 | # @example Building a dataset
6 | # builder = DatasetBuilder.new
7 | # builder.uri_endpoint = HydraTemplate.new('http://example.com/{?subject}')
8 | # dataset = builder.build
9 | #
10 | # dataset.dump :ttl
11 | # # a ,
12 | # # ;
13 | # # "http://example.com/{?subject}";
14 | # # [
15 | # # [
16 | # # ;
17 | # # "subject"
18 | # # ];
19 | # # "http://example.com/{?subject}"
20 | # # ] .
21 | class DatasetBuilder
22 | ##
23 | # @!attribute [r] control_mapping
24 | # @return [Control]
25 | # @!attribute [r] uri_root
26 | # @return [String] a URI-like string representing the root URI for the
27 | # dataset.
28 | # @see Settings#uri_root
29 | # @!attribute [rw] uri_endpoint
30 | # @return [HydraTemplate]
31 | attr_reader :control_mapping, :uri_endpoint, :uri_root
32 |
33 | ##
34 | # @param control_mapping [Control]
35 | # @param uri_endpoint [HydraTemplate]
36 | # @param uri_root [String] a URI-like string representing the root URI
37 | # for the dataset.
38 | def initialize(control_mapping: { 'subject' => RDF.subject },
39 | uri_endpoint: default_template,
40 | uri_root: Settings.uri_root)
41 | @control_mapping = control_mapping
42 | @uri_endpoint = uri_endpoint
43 | @uri_root = uri_root
44 | end
45 |
46 | ##
47 | # @return [Dataset] the dataset built from the current builder state
48 | def build
49 | Dataset.new(uri_root).tap do |dataset|
50 | dataset.uri_lookup_endpoint = uri_endpoint.to_s
51 | dataset.search = template_builder.new(dataset, uri_endpoint).build
52 |
53 | uri_endpoint.controls.each do |control|
54 | dataset.search.first.mapping <<
55 | control_builder.new(control, control_mapping[control]).build
56 | end
57 | end
58 | end
59 |
60 | private
61 |
62 | def control_builder
63 | ControlBuilder
64 | end
65 |
66 | def template_builder
67 | TemplateBuilder
68 | end
69 |
70 | def default_template
71 | LinkedDataFragments::HydraTemplate.new(Settings.uri_endpoint)
72 | end
73 | end
74 | end
75 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/builders/template_builder.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | ##
3 | # A Builder for Templates.
4 | class TemplateBuilder
5 | ##
6 | # @!attribute [r] dataset_node
7 | # @return [Dataset]
8 | # @!attribute [r] uri_template
9 | # @return [String]
10 | attr_reader :dataset_node, :uri_template
11 |
12 | ##
13 | # @param dataset_node [Dataset]
14 | # @param uri_template [#to_s]
15 | def initialize(dataset_node, uri_template)
16 | @dataset_node = dataset_node
17 | @uri_template = uri_template.to_s
18 | end
19 |
20 | def build
21 | Template.new(nil, dataset_node).tap do |template|
22 | template.template = self.uri_template
23 | end
24 | end
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/hydra_template.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | class HydraTemplate
3 | CONTROL_REGEX = /{\??(.*?)}/.freeze
4 |
5 | ##
6 | # @!attribute [r] template
7 | # @return [String]
8 | attr_reader :template
9 |
10 | ##
11 | # @param template [#to_s]
12 | def initialize(template)
13 | @template = template.to_s
14 | end
15 |
16 | ##
17 | # @return [Array] Array of controls in template.
18 | def controls
19 | @controls ||= template.scan(CONTROL_REGEX)
20 | .flatten # Reduce multiple matches
21 | .flat_map{|x| x.split(",")} # Split on commas for matches
22 | .map(&:strip) # Strip whitespace
23 | end
24 |
25 | ##
26 | # @return [String] the template
27 | def to_s
28 | @template.to_s
29 | end
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/marmotta.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | class Marmotta < BackendBase
3 |
4 | def initialize
5 | self.cache_backend_url = Setting.cache_backend_url
6 | self.cache_backend_context = Setting.cache_backend_context
7 | @connection = ::Marmotta::Connection.new(uri: Setting.cache_backend_url, context: Setting.cache_backend_context)
8 | end
9 |
10 | def retrieve(uri)
11 | resource = ::Marmotta::Resource.new(uri, connection: @connection)
12 | resulting_graph = resource.get
13 |
14 | return resulting_graph
15 | end
16 |
17 | def delete_all
18 | @connection.delete_all
19 | end
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/models.rb:
--------------------------------------------------------------------------------
1 | require 'linked_data_fragments/models/control'
2 | require 'linked_data_fragments/models/dataset'
3 | require 'linked_data_fragments/models/result'
4 | require 'linked_data_fragments/models/template'
5 |
6 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/models/control.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | class Control
3 | include ActiveTriples::RDFSource
4 | apply_schema LinkedDataFragments::ControlSchema
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/models/dataset.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | ##
3 | # An RDFSource of type `hydracore:Collection`. Implements the metadata schema
4 | # of `DatasetSchema`.
5 | class Dataset
6 | include ActiveTriples::RDFSource
7 |
8 | configure :type => [
9 | RDF::URI.intern("http://www.w3.org/ns/hydra/core#Collection"),
10 | RDF::Vocab::VOID.Dataset
11 | ]
12 |
13 | apply_schema LinkedDataFragments::DatasetSchema
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/models/result.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | class Result
3 | include ActiveTriples::RDFSource
4 | configure :type => [
5 | RDF::URI("http://www.w3.org/ns/hydra/core#Collection"),
6 | RDF::URI("http://www.w3.org/ns/hydra/core#PagedCollection")
7 | ]
8 |
9 | apply_schema LinkedDataFragments::ResultSchema
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/models/template.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | class Template
3 | include ActiveTriples::RDFSource
4 |
5 | apply_schema LinkedDataFragments::TemplateSchema
6 | end
7 | end
8 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/repository.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | ##
3 | # A basic `RDF::Repository` backend. This simply wraps RDF::Repository with
4 | # the smaller `BackendBase` interface.
5 | #
6 |
7 | # @example with a new in-memory repository
8 | # backend = LinkedDataFragments.new
9 | # backend.retrieve('http://example.com/moomin')
10 | #
11 | # @example with an existing repository instance
12 | # my_repository = RDF::Repository.new
13 | # backend = LinkedDataFragments.new(repository: my_repository)
14 | # backend.retrieve('http://example.com/moomin')
15 | #
16 | class Repository < BackendBase
17 | ##
18 | # @param repository [RDF::Repository] a repository instance
19 | def initialize(repository: RDF::Repository.new)
20 | @repo = repository
21 | end
22 |
23 | ##
24 | # @see BackendBase#add
25 | def add(uri)
26 | @repo.load(uri)
27 | end
28 |
29 | ##
30 | # Removes all resources from the backend.
31 | #
32 | # @return [void]
33 | def delete_all!
34 | @repo.clear
35 | end
36 |
37 | ##
38 | # @see BackendBase#empty?
39 | def empty?
40 | @repo.empty?
41 | end
42 |
43 | ##
44 | # @see BackendBase#has_resource?
45 | def has_resource?(uri)
46 | @repo.has_subject?(RDF::URI.new(uri))
47 | end
48 |
49 | ##
50 | # @see BackendBase#retrieve
51 | def retrieve(uri)
52 | @repo.load(uri) unless has_resource?(uri)
53 |
54 | resulting_graph = @repo.query(:subject => RDF::URI.new(uri))
55 | return resulting_graph
56 | end
57 | end
58 | end
59 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/schemas.rb:
--------------------------------------------------------------------------------
1 | require 'linked_data_fragments/schemas/control_schema'
2 | require 'linked_data_fragments/schemas/dataset_schema'
3 | require 'linked_data_fragments/schemas/result_schema'
4 | require 'linked_data_fragments/schemas/template_schema'
5 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/schemas/control_schema.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | ##
3 | # A HydraCore control schema
4 | class ControlSchema < ActiveTriples::Schema
5 | property :variable, :predicate => RDF::Vocab::HYDRA.variable
6 | property :property, :predicate => RDF::Vocab::HYDRA.property, :cast => false
7 | end
8 | end
9 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/schemas/dataset_schema.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | ##
3 | # A schema for `hydracore:Collection`/`Dataset` nodes.
4 | class DatasetSchema < ActiveTriples::Schema
5 | property :subset, predicate: RDF::Vocab::VOID.subset
6 | property :uri_lookup_endpoint, predicate: RDF::Vocab::VOID.uriLookupEndpoint
7 |
8 | # Change search so that it points to a search node.
9 | property :search, predicate: RDF::URI.intern("http://www.w3.org/ns/hydra/core#search")
10 | property :member, predicate: RDF::URI.intern("http://www.w3.org/ns/hydra/core#member")
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/schemas/result_schema.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | ##
3 | # Schema for Result model
4 | class ResultSchema < ActiveTriples::Schema
5 | property :subset, :predicate => RDF::Vocab::VOID.subset
6 |
7 | # Descriptive
8 | property :title, :predicate => RDF::Vocab::DC.title
9 | property :description, :predicate => RDF::Vocab::DC.description
10 | property :source, :predicate => RDF::Vocab::DC.source
11 |
12 | # Pagination
13 | property :triples_count, :predicate => RDF::Vocab::VOID.triples
14 | property :total_items, :predicate => RDF::URI("http://www.w3.org/ns/hydra/core#totalItems")
15 | property :items_per_page, :predicate => RDF::URI("http://www.w3.org/ns/hydra/core#itemsPerPage")
16 | property :first_page, :predicate => RDF::URI("http://www.w3.org/ns/hydra/core#firstPage")
17 | end
18 | end
19 |
20 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/schemas/template_schema.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | ##
3 | # Schema for template models
4 | class TemplateSchema < ActiveTriples::Schema
5 | property :template, :predicate => RDF::Vocab::HYDRA.search
6 | property :mapping, :predicate => RDF::Vocab::HYDRA.mapping
7 | end
8 | end
9 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/service.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | ##
3 | # The cache
4 | class Service
5 | include Singleton
6 |
7 | ##
8 | # @return [BackendBase]
9 | # @raise [BackendBase::UnsupportedBackend] when the configured repository is
10 | # not supported
11 | def cache
12 | @cache ||= BackendBase.for(name: Settings.cache_backend)
13 | rescue BackendBase::UnsupportedBackend
14 | raise BackendBase::UnsupportedBackend, 'Invalid cache_backend set in the yml config'
15 | end
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/lib/linked_data_fragments/settings.rb:
--------------------------------------------------------------------------------
1 | module LinkedDataFragments
2 | ##
3 | # A class to hold site-wide configuration.
4 | #
5 | # @todo Extract to a configuration file.
6 | class Settings
7 | class << self
8 | ##
9 | # @return [String]
10 | def app_root
11 | return @app_root if @app_root
12 | @app_root = Rails.root if defined?(Rails) and defined?(Rails.root)
13 | @app_root ||= APP_ROOT if defined?(APP_ROOT)
14 | @app_root ||= '.'
15 | end
16 |
17 | ##
18 | # @return [Hash] the settings from the YAML config
19 | # at {.config_path}.
20 | def config
21 | @config ||= YAML::load(File.open(config_path))
22 | .fetch(env) { raise "#{env} missing from ldf.yml" }
23 | .with_indifferent_access
24 | end
25 |
26 | ##
27 | # @return [String]
28 | def config_path
29 | File.join(app_root, 'config', 'ldf.yml')
30 | end
31 |
32 | ##
33 | # @return [String]
34 | def env
35 | return @env if @env
36 | #The following commented line always returns "test" in a rails c production console. Unsure of how to fix this yet...
37 | #@env = ENV["RAILS_ENV"] = "test" if ENV
38 | @env ||= Rails.env if defined?(Rails) and defined?(Rails.root)
39 | @env ||= 'development'
40 | end
41 |
42 | ##
43 | # @return [String]
44 | def uri_endpoint
45 | config[:uri_endpoint] || 'http://localhost:3000/{?subject}'
46 | end
47 |
48 | def uri_endpoint_route
49 | if uri_endpoint.match(/^http[s]*\:\/\/.+\//)
50 | endpoint = uri_endpoint.gsub(/^http[s]*\:\/\/[^\/]+/, '')
51 | endpoint.gsub!('{?subject}', '*subject')
52 | else
53 | #FIXME: What type of error should this be? Need to unit test this as well once figured out.
54 | raise ArgumentError, 'Invalid uri endpoint url specified'
55 | end
56 |
57 | endpoint
58 | end
59 |
60 | def uri_root
61 | config[:uri_root] || 'http://localhost:3000/#dataset'
62 | end
63 |
64 | def cache_backend
65 | config[:cache_backend][:provider] || 'marmotta'
66 | end
67 |
68 | def cache_backend_url
69 | config[:cache_backend][:url] || 'http://localhost:8988/marmotta'
70 | end
71 |
72 | def cache_backend_context
73 | config[:cache_backend][:context] || 'linked_data_fragments_unknown'
74 | end
75 | end
76 | end
77 | end
78 |
--------------------------------------------------------------------------------
/lib/tasks/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ActiveTriples/linked-data-fragments/a30e627cd079104a7e867c412f0e1cf77dcbf025/lib/tasks/.keep
--------------------------------------------------------------------------------
/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ActiveTriples/linked-data-fragments/a30e627cd079104a7e867c412f0e1cf77dcbf025/log/.keep
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The page you were looking for doesn't exist.
62 |
You may have mistyped the address or the page may have moved.
63 |
64 |
If you are the application owner check the logs for more information.
\n Sorry, but the requested resource could
51 | not be found in Marmotta right now, but may be available again in the future.
52 | Further details in the logs.\n
This domain is established to be used for illustrative examples in
61 | documents. You may use this\n domain in examples without prior coordination
62 | or asking for permission.
\n\n\n"
64 | http_version:
65 | recorded_at: Sat, 04 Feb 2017 04:22:38 GMT
66 | recorded_with: VCR 3.0.3
67 |
--------------------------------------------------------------------------------
/spec/cassettes/LinkedDataFragments_Repository/retrieve_a_subject_uri/should_retrieve_nothing_on_an_invalid_uri.yml:
--------------------------------------------------------------------------------
1 | ---
2 | http_interactions:
3 | - request:
4 | method: get
5 | uri: http://dbpedia.org/resource/BerlinInvalidAndNotReal
6 | body:
7 | encoding: US-ASCII
8 | string: ''
9 | headers:
10 | Accept:
11 | - text/turtle, text/rdf+turtle, application/turtle, application/x-turtle, application/ld+json,
12 | application/x-ld+json, application/n-triples, text/plain;q=0.5, application/n-quads,
13 | text/x-nquads, */*;q=0.1
14 | Accept-Encoding:
15 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16 | User-Agent:
17 | - Ruby
18 | response:
19 | status:
20 | code: 303
21 | message: See Other
22 | headers:
23 | Date:
24 | - Sat, 04 Feb 2017 04:24:31 GMT
25 | Content-Type:
26 | - text/turtle; qs=0.7
27 | Content-Length:
28 | - '0'
29 | Connection:
30 | - keep-alive
31 | Server:
32 | - Virtuoso/07.20.3217 (Linux) i686-generic-linux-glibc212-64 VDB
33 | Tcn:
34 | - choice
35 | Vary:
36 | - negotiate,accept
37 | Alternates:
38 | - '{"/data/BerlinInvalidAndNotReal.atom" 0.500000 {type application/atom+xml}},
39 | {"/data/BerlinInvalidAndNotReal.jrdf" 0.600000 {type application/rdf+json}},
40 | {"/data/BerlinInvalidAndNotReal.jsod" 0.500000 {type application/odata+json}},
41 | {"/data/BerlinInvalidAndNotReal.json" 0.600000 {type application/json}}, {"/data/BerlinInvalidAndNotReal.jsonld"
42 | 0.500000 {type application/ld+json}}, {"/data/BerlinInvalidAndNotReal.n3"
43 | 0.800000 {type text/n3}}, {"/data/BerlinInvalidAndNotReal.nt" 0.800000 {type
44 | text/rdf+n3}}, {"/data/BerlinInvalidAndNotReal.ttl" 0.700000 {type text/turtle}},
45 | {"/data/BerlinInvalidAndNotReal.xml" 0.950000 {type application/rdf+xml}}'
46 | Link:
47 | - ;rel="license",;
48 | rel="timegate"
49 | Location:
50 | - http://dbpedia.org/data/BerlinInvalidAndNotReal.ttl
51 | Expires:
52 | - Sat, 11 Feb 2017 04:24:31 GMT
53 | Cache-Control:
54 | - max-age=604800
55 | Access-Control-Allow-Origin:
56 | - "*"
57 | Access-Control-Allow-Credentials:
58 | - 'true'
59 | Access-Control-Allow-Methods:
60 | - GET, POST, OPTIONS
61 | Access-Control-Allow-Headers:
62 | - DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Accept-Encoding
63 | body:
64 | encoding: UTF-8
65 | string: ''
66 | http_version:
67 | recorded_at: Sat, 04 Feb 2017 04:22:51 GMT
68 | - request:
69 | method: get
70 | uri: http://dbpedia.org/data/BerlinInvalidAndNotReal.ttl
71 | body:
72 | encoding: US-ASCII
73 | string: ''
74 | headers:
75 | Accept:
76 | - text/turtle, text/rdf+turtle, application/turtle, application/x-turtle, application/ld+json,
77 | application/x-ld+json, application/n-triples, text/plain;q=0.5, application/n-quads,
78 | text/x-nquads, */*;q=0.1
79 | Accept-Encoding:
80 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
81 | User-Agent:
82 | - Ruby
83 | response:
84 | status:
85 | code: 200
86 | message: OK
87 | headers:
88 | Date:
89 | - Sat, 04 Feb 2017 04:24:31 GMT
90 | Content-Type:
91 | - text/turtle; charset=UTF-8
92 | Content-Length:
93 | - '15'
94 | Connection:
95 | - keep-alive
96 | Server:
97 | - Virtuoso/07.20.3217 (Linux) i686-generic-linux-glibc212-64 VDB
98 | Expires:
99 | - Sat, 11 Feb 2017 04:24:31 GMT
100 | Link:
101 | - ;rel="license",;
102 | rel="alternate"; type="application/rdf+xml"; title="Structured Descriptor
103 | Document (RDF/XML format)", ;
104 | rel="alternate"; type="text/n3"; title="Structured Descriptor Document (N3/Turtle
105 | format)", ; rel="alternate";
106 | type="application/json"; title="Structured Descriptor Document (RDF/JSON format)",
107 | ; rel="alternate"; type="application/atom+xml";
108 | title="OData (Atom+Feed format)", ;
109 | rel="alternate"; type="application/odata+json"; title="OData (JSON format)",
110 | ; rel="alternate"; type="text/html";
111 | title="XHTML+RDFa", ;
112 | rel="http://xmlns.com/foaf/0.1/primaryTopic", ;
113 | rev="describedby", ;
114 | rel="timegate"
115 | X-Sparql-Default-Graph:
116 | - http://dbpedia.org
117 | Cache-Control:
118 | - max-age=604800
119 | Access-Control-Allow-Origin:
120 | - "*"
121 | Access-Control-Allow-Credentials:
122 | - 'true'
123 | Access-Control-Allow-Methods:
124 | - GET, POST, OPTIONS
125 | Access-Control-Allow-Headers:
126 | - DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Accept-Encoding
127 | Accept-Ranges:
128 | - bytes
129 | body:
130 | encoding: UTF-8
131 | string: "# Empty TURTLE\n"
132 | http_version:
133 | recorded_at: Sat, 04 Feb 2017 04:22:52 GMT
134 | recorded_with: VCR 3.0.3
135 |
--------------------------------------------------------------------------------
/spec/controllers/dataset_controller_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe DatasetController do
4 | describe "index" do
5 |
6 | context "JSON-LD" do
7 | before do
8 | get :index, :format => :jsonld
9 | end
10 | it "should return a graph" do
11 | expect(JSON::LD::Reader.new(response.body).statements.to_a.length).not_to eq 0
12 | end
13 | it "should be JSON-LD" do
14 | expect(response.content_type).to eq "application/ld+json"
15 | end
16 | end
17 |
18 | context "n-triples" do
19 | before do
20 | get :index, :format => :nt
21 | end
22 | it "should return a graph" do
23 | expect(RDF::NTriples::Reader.new(response.body).statements.to_a.length).not_to eq 0
24 | end
25 | it "should be n-triples" do
26 | expect(response.content_type).to eq "application/n-triples"
27 | end
28 | end
29 |
30 | context "ttl" do
31 | before do
32 | get :index, :format => :ttl
33 | end
34 | it "should return a graph" do
35 | expect(RDF::Turtle::Reader.new(response.body).statements.to_a.length).not_to eq 0
36 | end
37 | it "should be n-triples" do
38 | expect(response.content_type).to eq "text/turtle"
39 | end
40 | end
41 |
42 | context "invalid" do
43 | it "should be of type 404 Routing Error" do
44 | expect{get :index, :format => :invalid}.to raise_error(ActionController::RoutingError)
45 | end
46 |
47 | it "should output valid response formats" do
48 | expect{get :index, :format => :invalid}.to raise_error(ActionController::RoutingError, /[ttl].+[application\/ld\+json]/)
49 | end
50 | end
51 |
52 | end
53 | end
54 |
--------------------------------------------------------------------------------
/spec/controllers/subject_controller_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe SubjectController do
4 |
5 | describe "settings" do
6 | #FIXME
7 | context "#cache_service" do
8 | it "should default be set to a valid service with a retrieve method" do
9 | expect(SubjectController.cache_service.respond_to?(:retrieve)).to eq true
10 | end
11 | end
12 |
13 | context "#routing" do
14 | it "should correctly return the subject route for various uri endpoints" do
15 |
16 | allow(Setting).to receive(:config).and_return({uri_endpoint: 'http://localhost:3000/{?subject}'})
17 | expect(Setting.uri_endpoint_route).to eq '/*subject'
18 |
19 | allow(Setting).to receive(:config).and_return({uri_endpoint: 'http://localhost:3000/subject/{?subject}'})
20 | expect(Setting.uri_endpoint_route).to eq '/subject/*subject'
21 |
22 | allow(Setting).to receive(:config).and_return({uri_endpoint: 'https://localhost:3000/long/a/{?subject}'})
23 | expect(Setting.uri_endpoint_route).to eq '/long/a/*subject'
24 |
25 | allow(Setting).to receive(:config).and_return({uri_endpoint: 'https://www.example.com:8888/fds/a/{?subject}'})
26 | expect(Setting.uri_endpoint_route).to eq '/fds/a/*subject'
27 |
28 | end
29 |
30 | it 'should error on an incorrect uri_endpoint setting' do
31 | #No http
32 | allow(Setting).to receive(:config).and_return({uri_endpoint: 'www.example.com:8888/fds/a/{?subject}'})
33 | expect{Setting.uri_endpoint_route}.to raise_error(ArgumentError)
34 |
35 | #No ending slash
36 | allow(Setting).to receive(:config).and_return({uri_endpoint: 'http://localhost:3000{?subject}'})
37 | expect{Setting.uri_endpoint_route}.to raise_error(ArgumentError)
38 | end
39 | end
40 |
41 | end
42 |
43 | describe "subject" do
44 |
45 | context "JSON-LD", :vcr do
46 | before do
47 | get :subject, {:subject => 'http://dbpedia.org/resource/Berlin',:format => :jsonld}
48 | end
49 | it "should return a graph" do
50 | expect(JSON::LD::Reader.new(response.body).statements.to_a.length).not_to eq 0
51 | end
52 | it "should be JSON-LD" do
53 | expect(response.content_type).to eq "application/ld+json"
54 | end
55 | end
56 |
57 | context "n-triples", :vcr do
58 | before do
59 | get :subject, {:subject => 'http://dbpedia.org/resource/Berlin', :format => :nt} #This breaks in Blazegraph? CHECKME
60 | end
61 | it "should return a graph" do
62 | expect(RDF::NTriples::Reader.new(response.body).statements.to_a.length).not_to eq 0
63 | end
64 | it "should be n-triples" do
65 | expect(response.content_type).to eq "application/n-triples"
66 | end
67 | end
68 |
69 | context "ttl", :vcr do
70 | before do
71 | get :subject, {:subject => 'http://dbpedia.org/resource/Berlin', :format => :ttl}
72 | end
73 | it "should return a graph" do
74 | expect(RDF::Turtle::Reader.new(response.body).statements.to_a.length).not_to eq 0
75 | end
76 | it "should be n-triples" do
77 | expect(response.content_type).to eq "text/turtle"
78 | end
79 | end
80 |
81 | context "invalid", :vcr do
82 | it "should be of type 404 Routing Error" do
83 | expect{get :subject, {:subject => 'http://dbpedia.org/resource/Berlin', :format => :invalid}}.to raise_error(ActionController::RoutingError)
84 | end
85 |
86 | it "should output valid response formats" do
87 | expect{get :subject, {:subject => 'http://dbpedia.org/resource/Berlin', :format => :invalid}}.to raise_error(ActionController::RoutingError, /[ttl].+[application\/ld\+json]/)
88 | end
89 | end
90 |
91 | end
92 | end
93 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/builders/control_builder_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | require 'linked_data_fragments/builders'
4 |
5 | describe LinkedDataFragments::ControlBuilder do
6 | subject { described_class.new(control, property) }
7 |
8 | let(:control) { "subject" }
9 | let(:property) { RDF.subject }
10 |
11 | describe '#control' do
12 | it { expect(subject.control).to eq control }
13 | end
14 |
15 | describe '#property' do
16 | it { expect(subject.property).to eq property }
17 | end
18 |
19 | describe "#build" do
20 | let(:result) { subject.build }
21 |
22 | it "should return a control with a variable" do
23 | expect(result.variable).to contain_exactly control
24 | end
25 |
26 | it "should return a control with a property" do
27 | expect(result.property).to contain_exactly property
28 | end
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/builders/dataset_builder_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | require 'linked_data_fragments/builders'
4 |
5 | describe LinkedDataFragments::DatasetBuilder do
6 | subject { described_class.new(**opts) }
7 |
8 | let(:opts) { {} }
9 |
10 | describe '#build' do
11 | let(:result) { subject.build }
12 |
13 | it 'assigns uri endpoint' do
14 | expect(result.uri_lookup_endpoint)
15 | .to contain_exactly(subject.uri_endpoint.to_s)
16 | end
17 |
18 | it 'has the appropriate subject' do
19 | expect(result.rdf_subject).to eq RDF::URI(subject.uri_root)
20 | end
21 |
22 | it 'has a search endpoint with a template' do
23 | expect(result.search.first.template.first)
24 | .to eq subject.uri_endpoint.to_s
25 | end
26 |
27 | it 'has a search endpoint with mappings' do
28 | expect(result.search.first.mapping.first.property)
29 | .to contain_exactly(RDF.subject)
30 | end
31 |
32 | context 'with values' do
33 | let(:opts) do
34 | { uri_endpoint: template, uri_root: root, control_mapping: mapping }
35 | end
36 |
37 | let(:mapping) { { 'object' => RDF.object } }
38 | let(:root) { 'http://example.com/my_dataset/' }
39 | let(:template) { LinkedDataFragments::HydraTemplate.new( "#{root}{?object}") }
40 |
41 | it 'has the paramaterized endpoint' do
42 | expect(result.uri_lookup_endpoint).to contain_exactly template.to_s
43 | end
44 |
45 | it 'has the paramaterized subject' do
46 | expect(result.rdf_subject).to eq RDF::URI(root)
47 | end
48 |
49 | it 'has a search endpoint with the paramaterized template' do
50 | expect(result.search.first.template)
51 | .to contain_exactly(template.to_s)
52 | end
53 |
54 | it 'has a search endpoint with parameterized mappings' do
55 | expect(result.search.first.mapping.first.property)
56 | .to contain_exactly(RDF.object)
57 | end
58 | end
59 | end
60 |
61 | describe '#uri_endpoint' do
62 | it 'defaults to configured value' do
63 | expect(subject.uri_endpoint.to_s)
64 | .to eq LinkedDataFragments::Settings.uri_endpoint
65 | end
66 |
67 | it 'default manifests as HydraTemplate instance' do
68 | expect(subject.uri_endpoint)
69 | .to be_a LinkedDataFragments::HydraTemplate
70 | end
71 | end
72 |
73 | describe '#uri_root' do
74 | it 'defaults to the configured value' do
75 | expect(subject.uri_root).to eq LinkedDataFragments::Settings.uri_root
76 | end
77 | end
78 | end
79 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/builders/template_builder_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | require 'linked_data_fragments/builders'
4 |
5 | describe LinkedDataFragments::TemplateBuilder do
6 | subject { described_class.new(node, template) }
7 |
8 | let(:node) { LinkedDataFragments::Dataset.new }
9 | let(:template) { 'http://localhost:4000/{?subject}' }
10 |
11 | describe '#build' do
12 | it 'builds a template with the node as parent' do
13 | expect(subject.build.parent).to eql node
14 | end
15 |
16 | it 'sets #template to on built template' do
17 | expect(subject.build.template).to contain_exactly template
18 | end
19 | end
20 |
21 | describe '#dataset_node' do
22 | it { expect(subject.dataset_node).to eql node }
23 | end
24 |
25 | describe '#uri_template' do
26 | it { expect(subject.uri_template).to eql template }
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/hydra_template_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe LinkedDataFragments::HydraTemplate do
4 | subject { described_class.new(template) }
5 | let(:template) { 'http://localhost:4000/{?subject}' }
6 |
7 | describe '#controls' do
8 | it 'should return the mapped controls' do
9 | expect(subject.controls).to eq ['subject']
10 | end
11 |
12 | context 'when given multiple controls' do
13 | let(:template) { 'http://localhost:4000/{?subject,predicate, object}' }
14 |
15 | it 'should return all of them' do
16 | expect(subject.controls).to eq ['subject', 'predicate', 'object']
17 | end
18 | end
19 |
20 | context 'with no controls' do
21 | let(:template) { 'http://localhost:4000' }
22 |
23 | it 'should return an empty array' do
24 | expect(subject.controls).to be_empty
25 | end
26 | end
27 |
28 | context 'with slashes to separate controls' do
29 | let(:template) { 'http://localhost:4000/{subject}/{predicate}' }
30 |
31 | it 'should return them' do
32 | expect(subject.controls).to eq ['subject', 'predicate']
33 | end
34 | end
35 | end
36 |
37 | describe '#to_s' do
38 | it 'should be the template' do
39 | expect(subject.to_s).to eql template
40 | end
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/models/control_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | require 'linked_data_fragments/models'
4 |
5 | describe LinkedDataFragments::Control do
6 | subject { described_class.new }
7 |
8 | it 'should apply the control schema' do
9 | LinkedDataFragments::ControlSchema.properties.each do |property|
10 | expect(subject.class.properties[property.name.to_s].predicate)
11 | .to eq property.predicate
12 | end
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/models/dataset_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | require 'linked_data_fragments/models'
4 |
5 | describe LinkedDataFragments::Dataset do
6 | subject { described_class.new(uri) }
7 | let(:uri) { 'http://localhost:3000#dataset' }
8 |
9 | describe '#type' do
10 | it 'should be a hydra collection' do
11 | expect(subject.type)
12 | .to include RDF::URI('http://www.w3.org/ns/hydra/core#Collection')
13 | end
14 |
15 | it 'should be a dataset' do
16 | expect(subject.type)
17 | .to include RDF::URI('http://rdfs.org/ns/void#Dataset')
18 | end
19 | end
20 |
21 | it 'should apply the dataset schema' do
22 | LinkedDataFragments::DatasetSchema.properties.each do |property|
23 | expect(subject.class.properties[property.name.to_s].predicate).to eq property.predicate
24 | end
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/models/result_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | require 'linked_data_fragments/models'
4 |
5 | describe LinkedDataFragments::Result do
6 | subject { described_class.new(root_uri) }
7 |
8 | let(:root_uri) { 'http://localhost:3000' }
9 |
10 | describe '#rdf_subject' do
11 | it 'should be the passed URI' do
12 | expect(subject.rdf_subject).to eq RDF::URI(root_uri)
13 | end
14 | end
15 |
16 | describe '#type' do
17 | it "should be a hydra collection" do
18 | expect(subject.type)
19 | .to include RDF::URI('http://www.w3.org/ns/hydra/core#Collection')
20 | end
21 |
22 | it "should be a paged collection" do
23 | expect(subject.type)
24 | .to include RDF::URI('http://www.w3.org/ns/hydra/core#PagedCollection')
25 | end
26 | end
27 |
28 | it 'should apply the Result schema' do
29 | LinkedDataFragments::ResultSchema.properties.each do |property|
30 | expect(subject.class.properties[property.name.to_s].predicate)
31 | .to eq property.predicate
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/models/template_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | require 'linked_data_fragments/models'
4 |
5 | describe LinkedDataFragments::Template do
6 | subject { described_class.new(uri) }
7 | let(:uri) { RDF::Node.new('triplePattern') }
8 |
9 | it 'should apply the template schema' do
10 | LinkedDataFragments::TemplateSchema.properties.each do |property|
11 | expect(subject.class.properties[property.name.to_s].predicate)
12 | .to eq property.predicate
13 | end
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/schemas/control_schema_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe LinkedDataFragments::ControlSchema do
4 | it_behaves_like 'a schema', [:variable, :property]
5 | end
6 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/schemas/dataset_schema_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe LinkedDataFragments::DatasetSchema do
4 | it_behaves_like 'a schema', [:subset, :uri_lookup_endpoint, :search, :member]
5 | end
6 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/schemas/result_schema_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe LinkedDataFragments::ResultSchema do
4 | it_behaves_like 'a schema', [:subset,
5 | :title,
6 | :description,
7 | :source,
8 | :triples_count,
9 | :total_items,
10 | :items_per_page,
11 | :first_page
12 | ]
13 | end
14 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/schemas/template_schema_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe LinkedDataFragments::TemplateSchema do
4 | it_behaves_like 'a schema', [:template, :mapping]
5 | end
6 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/service_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | require 'linked_data_fragments/service'
4 | require 'linked_data_fragments/repository'
5 |
6 | describe LinkedDataFragments::Service do
7 | subject { described_class.instance }
8 |
9 | before do
10 | # @todo: REMOVE THIS HACKY STUB
11 | allow(LinkedDataFragments::Settings)
12 | .to receive(:cache_backend)
13 | .and_return(:repository)
14 | end
15 |
16 | describe '#cache' do
17 | it 'gives a backend' do
18 | expect(subject.cache).to respond_to :retrieve
19 | end
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/spec/linked_data_fragments/settings_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe LinkedDataFragments::Settings do
4 | describe '.app_root' do
5 | it 'gives a relative path string "." by default'
6 | it 'when called within a rails app gives Rails.root'
7 | it 'gives APP_ROOT when available'
8 | end
9 |
10 | describe '.config' do
11 | it 'loads the config file'
12 | end
13 |
14 | describe '.config_path' do
15 | it 'gives the config file path' do
16 | expect(described_class.config_path)
17 | .to eq "#{described_class.app_root}/config/ldf.yml"
18 | end
19 | end
20 |
21 | describe '.env' do
22 | it 'defaults to "development"'
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/spec/rails_helper.rb:
--------------------------------------------------------------------------------
1 | # This file is copied to spec/ when you run 'rails generate rspec:install'
2 | ENV['RAILS_ENV'] ||= 'test'
3 | require 'spec_helper'
4 | require File.expand_path('../../config/environment', __FILE__)
5 | require 'rspec/rails'
6 | # Add additional requires below this line. Rails is not loaded until this point!
7 |
8 | # Requires supporting ruby files with custom matchers and macros, etc, in
9 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
10 | # run as spec files by default. This means that files in spec/support that end
11 | # in _spec.rb will both be required and run as specs, causing the specs to be
12 | # run twice. It is recommended that you do not name files matching this glob to
13 | # end with _spec.rb. You can configure this pattern with the --pattern
14 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
15 | #
16 | # The following line is provided for convenience purposes. It has the downside
17 | # of increasing the boot-up time by auto-requiring all files in the support
18 | # directory. Alternatively, in the individual `*_spec.rb` files, manually
19 | # require only the support files necessary.
20 | #
21 | # Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
22 |
23 | # Checks for pending migrations before tests are run.
24 | # If you are not using ActiveRecord, you can remove this line.
25 | ActiveRecord::Migration.maintain_test_schema!
26 |
27 | RSpec.configure do |config|
28 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
29 | config.fixture_path = "#{::Rails.root}/spec/fixtures"
30 |
31 | # If you're not using ActiveRecord, or you'd prefer not to run each of your
32 | # examples within a transaction, remove the following line or assign false
33 | # instead of true.
34 | config.use_transactional_fixtures = true
35 |
36 | # RSpec Rails can automatically mix in different behaviours to your tests
37 | # based on their file location, for example enabling you to call `get` and
38 | # `post` in specs under `spec/controllers`.
39 | #
40 | # You can disable this behaviour by removing the line below, and instead
41 | # explicitly tag your specs with their type, e.g.:
42 | #
43 | # RSpec.describe UsersController, :type => :controller do
44 | # # ...
45 | # end
46 | #
47 | # The different available types are documented in the features, such as in
48 | # https://relishapp.com/rspec/rspec-rails/docs
49 | config.infer_spec_type_from_file_location!
50 | end
51 |
--------------------------------------------------------------------------------
/spec/routing/root_routing_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe "root routes" do
4 | it "should navigate to the dataset controller" do
5 | expect(get "/").to route_to :controller => "dataset", :action => "index"
6 | end
7 | end
8 |
--------------------------------------------------------------------------------
/spec/routing/subject_routing_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe "subject routes" do
4 | it "should navigate to the subject controller on a single subject param" do
5 | expect(get "/http://dbpedia.org/resource/Berlin").to route_to :controller => "subject", :action => "subject", :subject=>"http://dbpedia.org/resource/Berlin"
6 | end
7 | it "should navigate to the subject controller even if it's a root URI" do
8 | expect(get "/http://dbpedia.org").to route_to :controller => "subject", :action => "subject", :subject => "http://dbpedia.org"
9 | end
10 | it "should navigate to the subject controller if a good format is provided" do
11 | expect(get "/http://dbpedia.org.ttl").to route_to :controller => "subject", :action => "subject", :subject => "http://dbpedia.org", :format => "ttl"
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require 'vcr_setup'
2 | require 'linked_data_fragments'
3 |
4 | Dir['./spec/support/**/*.rb'].each { |f| require f }
5 |
6 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all
7 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8 | # The generated `.rspec` file contains `--require spec_helper` which will cause
9 | # this file to always be loaded, without a need to explicitly require it in any
10 | # files.
11 | #
12 | # Given that it is always loaded, you are encouraged to keep this file as
13 | # light-weight as possible. Requiring heavyweight dependencies from this file
14 | # will add to the boot time of your test suite on EVERY test run, even for an
15 | # individual file that may not need all of that loaded. Instead, consider making
16 | # a separate helper file that requires the additional dependencies and performs
17 | # the additional setup, and require it from the spec files that actually need
18 | # it.
19 | #
20 | # The `.rspec` file also contains a few flags that are not defaults but that
21 | # users commonly want.
22 | #
23 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
24 | RSpec.configure do |config|
25 | # rspec-expectations config goes here. You can use an alternate
26 | # assertion/expectation library such as wrong or the stdlib/minitest
27 | # assertions if you prefer.
28 | config.expect_with :rspec do |expectations|
29 | # This option will default to `true` in RSpec 4. It makes the `description`
30 | # and `failure_message` of custom matchers include text for helper methods
31 | # defined using `chain`, e.g.:
32 | # be_bigger_than(2).and_smaller_than(4).description
33 | # # => "be bigger than 2 and smaller than 4"
34 | # ...rather than:
35 | # # => "be bigger than 2"
36 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true
37 | end
38 |
39 | # rspec-mocks config goes here. You can use an alternate test double
40 | # library (such as bogus or mocha) by changing the `mock_with` option here.
41 | config.mock_with :rspec do |mocks|
42 | # Prevents you from mocking or stubbing a method that does not exist on
43 | # a real object. This is generally recommended, and will default to
44 | # `true` in RSpec 4.
45 | mocks.verify_partial_doubles = true
46 | end
47 |
48 | config.before(:each) do
49 | # @todo: Eliminate this.
50 | if Object.const_defined?('Setting')
51 | allow(Setting).to receive(:cache_backend).and_return('repository')
52 | end
53 | end
54 |
55 | # The settings below are suggested to provide a good initial experience
56 | # with RSpec, but feel free to customize to your heart's content.
57 | =begin
58 | # These two settings work together to allow you to limit a spec run
59 | # to individual examples or groups you care about by tagging them with
60 | # `:focus` metadata. When nothing is tagged with `:focus`, all examples
61 | # get run.
62 | config.filter_run :focus
63 | config.run_all_when_everything_filtered = true
64 |
65 | # Limits the available syntax to the non-monkey patched syntax that is
66 | # recommended. For more details, see:
67 | # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
68 | # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69 | # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
70 | config.disable_monkey_patching!
71 |
72 | # Many RSpec users commonly either run the entire suite or an individual
73 | # file, and it's useful to allow more verbose output when running an
74 | # individual spec file.
75 | if config.files_to_run.one?
76 | # Use the documentation formatter for detailed output,
77 | # unless a formatter has already been configured
78 | # (e.g. via a command-line flag).
79 | config.default_formatter = 'doc'
80 | end
81 |
82 | # Print the 10 slowest examples and example groups at the
83 | # end of the spec run, to help surface which specs are running
84 | # particularly slow.
85 | config.profile_examples = 10
86 |
87 | # Run specs in random order to surface order dependencies. If you find an
88 | # order dependency and want to debug it, you can fix the order by providing
89 | # the seed, which is printed after each run.
90 | # --seed 1234
91 | config.order = :random
92 |
93 | # Seed global randomization in this process using the `--seed` CLI option.
94 | # Setting this allows you to use `--seed` to deterministically reproduce
95 | # test failures related to randomization by passing the same `--seed` value
96 | # as the one that triggered the failure.
97 | Kernel.srand config.seed
98 | =end
99 | end
100 |
--------------------------------------------------------------------------------
/spec/support/shared_examples/backend.rb:
--------------------------------------------------------------------------------
1 | shared_examples 'a backend' do
2 | let(:url) { 'http://dbpedia.org/resource/Berlin' }
3 |
4 | after { subject.delete_all! }
5 |
6 | describe '.for' do
7 | it 'defaults to Repostiory' do
8 | expect(described_class.for)
9 | .to be_a LinkedDataFragments::Repository
10 | end
11 |
12 | it 'raises ArgumentError when name does not exist' do
13 | expect { described_class.for(name: :totally_fake) }
14 | .to raise_error LinkedDataFragments::BackendBase::UnsupportedBackend
15 | end
16 | end
17 |
18 | describe '#add', :vcr do
19 | it 'adds a url' do
20 | expect { subject.add(url) }
21 | .to change { subject.has_resource?(url) }.from(false).to(true)
22 | end
23 | end
24 |
25 | describe '#cache_backend_context' do
26 | let(:context) { 'http://example.com/my_named_graph' }
27 |
28 | it 'has a backend context' do
29 | unless subject.cache_backend_context.nil?
30 | expect(subject.cache_backend_context).to be_a String
31 | end
32 | end
33 |
34 | it 'sets backend context' do
35 | expect { subject.cache_backend_context = context }
36 | .to change { subject.cache_backend_context }.to eq context
37 | end
38 | end
39 |
40 | describe '#cache_backend_url' do
41 | it 'has a backend url' do
42 | unless subject.cache_backend_url.nil?
43 | expect(subject.cache_backend_url).to be_a String
44 | end
45 | end
46 |
47 | it 'sets backend url' do
48 | expect { subject.cache_backend_url = url }
49 | .to change { subject.cache_backend_url }.to eq url
50 | end
51 | end
52 |
53 | describe '#delete_all!', :vcr do
54 | it 'removes resources' do
55 | subject.add(url)
56 |
57 | expect { subject.delete_all! }
58 | .to change { subject.has_resource?(url) }.from(true).to(false)
59 | end
60 |
61 | it 'empties backend' do
62 | subject.add(url)
63 |
64 | expect { subject.delete_all! }
65 | .to change { subject.empty? }.from(false).to(true)
66 | end
67 | end
68 |
69 | describe '#empty?', :vcr do
70 | it 'becomes non-empty when a resource is added' do
71 | expect { subject.add(url) }
72 | .to change { subject.empty? }.from(true).to(false)
73 | end
74 | end
75 |
76 | describe '#has?', :vcr do
77 | it 'has a resource that has been added' do
78 | subject.add(url)
79 |
80 | expect(subject).to have_resource url
81 | end
82 | end
83 |
84 | describe '#retrieve' do
85 | context 'when empty', :vcr do
86 | it 'loads a valid URL' do
87 | expect(subject.retrieve(url)).to respond_to :each_statement
88 | end
89 |
90 | it 'raises on invalid URL' do
91 | expect { subject.retrieve('http://example.com/moomin') }
92 | .to raise_error IOError
93 | end
94 | end
95 |
96 | context 'with an existing resource', :vcr do
97 | before { subject.add(url) }
98 |
99 | it 'gets an RDF::Enumerable' do
100 | expect(subject.retrieve(url)).to respond_to :each_statement
101 | end
102 |
103 | it 'raises IOError on invalid URL' do
104 | expect { subject.retrieve('http://example.com/moomin') }
105 | .to raise_error IOError
106 | end
107 | end
108 | end
109 | end
110 |
--------------------------------------------------------------------------------
/spec/support/shared_examples/schema.rb:
--------------------------------------------------------------------------------
1 | shared_examples 'a schema' do |properties|
2 | let(:fake_source) do
3 | klass = Class.new { include ActiveTriples::RDFSource }
4 | klass.apply_schema described_class
5 | klass
6 | end
7 |
8 | let(:source) { fake_source.new }
9 | let(:value) { :moomin }
10 |
11 | properties.each do |property|
12 | it "has configured property #{property}" do
13 | expect { source.send("#{property}=".to_sym, value) }
14 | .to change { source.send(property).to_a }
15 | .to contain_exactly(value)
16 | end
17 | end
18 | end
19 |
--------------------------------------------------------------------------------
/spec/vcr_setup.rb:
--------------------------------------------------------------------------------
1 | require 'webmock/rspec'
2 | require 'vcr'
3 |
4 | VCR.configure do |c|
5 | c.cassette_library_dir = 'spec/cassettes'
6 | c.hook_into :webmock
7 | c.configure_rspec_metadata!
8 | end
--------------------------------------------------------------------------------
/vendor/assets/javascripts/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ActiveTriples/linked-data-fragments/a30e627cd079104a7e867c412f0e1cf77dcbf025/vendor/assets/javascripts/.keep
--------------------------------------------------------------------------------
/vendor/assets/stylesheets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ActiveTriples/linked-data-fragments/a30e627cd079104a7e867c412f0e1cf77dcbf025/vendor/assets/stylesheets/.keep
--------------------------------------------------------------------------------