Skip to content

Commit cde2c60

Browse files
committed
Convert to an engine
Also switch testing from Circle to Travis-CI
1 parent 1450161 commit cde2c60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+8971
-11829
lines changed

Diff for: .gitignore

+10-30
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
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
1+
/.bundle/
2+
/.yardoc
203
/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
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/tmp/
10+
11+
.internal_test_app

Diff for: .rspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
--format documentation
12
--color
2-
--require spec_helper

Diff for: .travis.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
notifications:
2+
email: false
3+
4+
rvm:
5+
- 2.2.4
6+
- 2.3.0
7+
8+
notifications:
9+
irc: "irc.freenode.org#blacklight"
10+
11+
env:
12+
global:
13+
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
14+
15+
sudo: false
16+
language: ruby
17+
18+
script:
19+
- bundle exec rake --trace

Diff for: Gemfile

+35-64
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,38 @@
11
source 'https://rubygems.org'
22

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-
# Access an IRB console on exception pages or by using <%= console %> in views
61-
gem 'web-console', '~> 2.0'
62-
end
63-
64-
group :test do
65-
gem 'vcr'
66-
gem 'webmock'
3+
# Specify your gem's dependencies in linked-data-fragments.gemspec
4+
gemspec
5+
# BEGIN ENGINE_CART BLOCK
6+
# engine_cart: 0.8.2
7+
# engine_cart stanza: 0.8.0
8+
# the below comes from engine_cart, a gem used to test this Rails engine gem in the context of a Rails app.
9+
file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path(".internal_test_app", File.dirname(__FILE__)))
10+
if File.exist?(file)
11+
begin
12+
eval_gemfile file
13+
rescue Bundler::GemfileError => e
14+
Bundler.ui.warn '[EngineCart] Skipping Rails application dependencies:'
15+
Bundler.ui.warn e.message
16+
end
17+
else
18+
Bundler.ui.warn "[EngineCart] Unable to find test application dependencies in #{file}, using placeholder dependencies"
19+
20+
if ENV['RAILS_VERSION']
21+
if ENV['RAILS_VERSION'] == 'edge'
22+
gem 'rails', github: 'rails/rails'
23+
ENV['ENGINE_CART_RAILS_OPTIONS']= "--edge --skip-turbolinks"
24+
else
25+
gem 'rails', ENV['RAILS_VERSION']
26+
end
27+
end
28+
29+
if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^4.2/
30+
gem 'responders', "~> 2.0"
31+
gem 'sass-rails', ">= 5.0"
32+
elsif ENV['RAILS_VERSION'] =~ /^5.0/ || ENV['RAILS_VERSION'] == 'edge'
33+
# nop
34+
else
35+
gem 'sass-rails', "< 5.0"
36+
end
6737
end
38+
# END ENGINE_CART BLOCK

Diff for: Rakefile

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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.
1+
require "bundler/gem_tasks"
2+
require "rspec/core/rake_task"
3+
require 'engine_cart/rake_task'
34

4-
require File.expand_path('../config/application', __FILE__)
5+
RSpec::Core::RakeTask.new(:spec)
56

6-
Rails.application.load_tasks
7+
task ci: ['engine_cart:generate', :spec]
8+
task default: [:ci]

Diff for: app/controllers/application_controller.rb

-34
This file was deleted.

Diff for: app/controllers/dataset_controller.rb

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module LinkedDataFragments
2+
##
3+
# Inherit from the host app's ApplicationController
4+
class ApplicationController < ::ApplicationController
5+
before_action :verify_format
6+
7+
def verify_format
8+
if !renderer_mapping.keys.include?(request.format.symbol)
9+
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")
10+
end
11+
end
12+
13+
14+
def self.renderer_mapping
15+
{
16+
:nt => lambda { |data| data.dump(:ntriples) },
17+
:jsonld => lambda { |data| data.dump(:jsonld, :standard_prefixes => true) },
18+
:ttl => lambda { |data| data.dump(:ttl) }
19+
}
20+
end
21+
22+
def renderer_mapping
23+
self.class.renderer_mapping
24+
end
25+
26+
def renderer_mapping_to_strings
27+
renderer_mapping.map do |format, renderer|
28+
Mime::Type.lookup_by_extension(format).to_s
29+
end
30+
end
31+
end
32+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module LinkedDataFragments
2+
class DatasetController < LinkedDataFragments::ApplicationController
3+
def index
4+
@data = built_dataset
5+
6+
respond_to do |f|
7+
renderer_mapping.each do |format, renderer|
8+
f.send(format) do
9+
render :text => renderer.call(@data)
10+
end
11+
end
12+
end
13+
end
14+
15+
private
16+
17+
def built_dataset
18+
DatasetBuilder.new.build
19+
end
20+
end
21+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module LinkedDataFragments
2+
class SubjectController < LinkedDataFragments::ApplicationController
3+
before_action :fix_passed_params
4+
5+
def self.cache_service
6+
@cache || assign_cache_service
7+
end
8+
9+
def self.assign_cache_service
10+
case Setting.cache_backend
11+
when 'marmotta'
12+
@cache = LinkedDataFragments::Marmotta.new
13+
when 'repository'
14+
@cache = LinkedDataFragments::Repository.new
15+
when 'blazegraph'
16+
@cache = LinkedDataFragments::Blazegraph.new
17+
else
18+
#FIXME: What type of error should this be? Need to unit test this as well once figured out.
19+
raise ArgumentError, 'Invalid cache_backend set in the yml config'
20+
end
21+
return @cache
22+
end
23+
24+
def subject
25+
@data = SubjectController.cache_service.retrieve(params[:subject])
26+
27+
respond_to do |f|
28+
renderer_mapping.each do |format, renderer|
29+
f.send(format) do
30+
render :text => renderer.call(@data)
31+
end
32+
end
33+
end
34+
35+
end
36+
37+
def fix_passed_params
38+
#Seems like a double '//' in the captured param is changed to a single one. Unsure of how better to do this...
39+
single_slash_match = params[:subject].match(/^http[s]*\:\/(?!\/)/)
40+
if single_slash_match.present?
41+
params[:subject] = params[:subject][0..single_slash_match[0].length-1] + '/' + params[:subject][single_slash_match[0].length..params[:subject].length]
42+
end
43+
end
44+
end
45+
end

Diff for: app/controllers/subject_controller.rb

-45
This file was deleted.

0 commit comments

Comments
 (0)