Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] convert to an engine #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 10 additions & 30 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*
!/log/.keep
/tmp

#Ignore the lock file so we can more easily all have different gems
/.bundle/
/.yardoc
/Gemfile.lock

#Ignore Rubymine and jetty files
/.idea
/jetty
/ldf-jetty

#Ignore yml files
/*.yml

# Ignore LDF config
config/ldf.yml
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

.internal_test_app
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--format documentation
--color
--require spec_helper
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
notifications:
email: false

rvm:
- 2.2.4
- 2.3.0

notifications:
irc: "irc.freenode.org#blacklight"

env:
global:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true

sudo: false
language: ruby

script:
- bundle exec rake --trace
99 changes: 35 additions & 64 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,67 +1,38 @@
source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

gem 'responders'
gem 'rdf'
gem 'rdf-turtle'
gem 'json-ld', '~> 1.99'
#gem 'json-ld'
gem 'active-triples'
#gem 'rdf-vocab', github: "ruby-rdf/rdf-vocab", branch: "develop"
gem 'rdf-vocab', '0.8.7.1'
gem 'jettywrapper', '>= 2.0.0'
gem 'marmotta'
gem 'ldfwrapper', github: 'boston-library/ldf-wrapper', branch: "master"
gem 'rdf-blazegraph'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'

gem 'rspec-rails'
gem 'pry-byebug'
end

group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
end

group :test do
gem 'vcr'
gem 'webmock'
# Specify your gem's dependencies in linked-data-fragments.gemspec
gemspec
# BEGIN ENGINE_CART BLOCK
# engine_cart: 0.8.2
# engine_cart stanza: 0.8.0
# the below comes from engine_cart, a gem used to test this Rails engine gem in the context of a Rails app.
file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path(".internal_test_app", File.dirname(__FILE__)))
if File.exist?(file)
begin
eval_gemfile file
rescue Bundler::GemfileError => e
Bundler.ui.warn '[EngineCart] Skipping Rails application dependencies:'
Bundler.ui.warn e.message
end
else
Bundler.ui.warn "[EngineCart] Unable to find test application dependencies in #{file}, using placeholder dependencies"

if ENV['RAILS_VERSION']
if ENV['RAILS_VERSION'] == 'edge'
gem 'rails', github: 'rails/rails'
ENV['ENGINE_CART_RAILS_OPTIONS']= "--edge --skip-turbolinks"
else
gem 'rails', ENV['RAILS_VERSION']
end
end

if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^4.2/
gem 'responders', "~> 2.0"
gem 'sass-rails', ">= 5.0"
elsif ENV['RAILS_VERSION'] =~ /^5.0/ || ENV['RAILS_VERSION'] == 'edge'
# nop
else
gem 'sass-rails', "< 5.0"
end
end
# END ENGINE_CART BLOCK
10 changes: 6 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'engine_cart/rake_task'

require File.expand_path('../config/application', __FILE__)
RSpec::Core::RakeTask.new(:spec)

Rails.application.load_tasks
task ci: ['engine_cart:generate', :spec]
task default: [:ci]
34 changes: 0 additions & 34 deletions app/controllers/application_controller.rb

This file was deleted.

22 changes: 0 additions & 22 deletions app/controllers/dataset_controller.rb

This file was deleted.

32 changes: 32 additions & 0 deletions app/controllers/linked_data_fragments/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module LinkedDataFragments
##
# Inherit from the host app's ApplicationController
class ApplicationController < ::ApplicationController
before_action :verify_format

def verify_format
if !renderer_mapping.keys.include?(request.format.symbol)
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")
end
end


def self.renderer_mapping
{
:nt => lambda { |data| data.dump(:ntriples) },
:jsonld => lambda { |data| data.dump(:jsonld, :standard_prefixes => true) },
:ttl => lambda { |data| data.dump(:ttl) }
}
end

def renderer_mapping
self.class.renderer_mapping
end

def renderer_mapping_to_strings
renderer_mapping.map do |format, renderer|
Mime::Type.lookup_by_extension(format).to_s
end
end
end
end
21 changes: 21 additions & 0 deletions app/controllers/linked_data_fragments/dataset_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module LinkedDataFragments
class DatasetController < LinkedDataFragments::ApplicationController
def index
@data = built_dataset

respond_to do |f|
renderer_mapping.each do |format, renderer|
f.send(format) do
render :text => renderer.call(@data)
end
end
end
end

private

def built_dataset
DatasetBuilder.new.build
end
end
end
45 changes: 45 additions & 0 deletions app/controllers/linked_data_fragments/subject_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module LinkedDataFragments
class SubjectController < LinkedDataFragments::ApplicationController
before_action :fix_passed_params

def self.cache_service
@cache || assign_cache_service
end

def self.assign_cache_service
case Setting.cache_backend
when 'marmotta'
@cache = LinkedDataFragments::Marmotta.new
when 'repository'
@cache = LinkedDataFragments::Repository.new
when 'blazegraph'
@cache = LinkedDataFragments::Blazegraph.new
else
#FIXME: What type of error should this be? Need to unit test this as well once figured out.
raise ArgumentError, 'Invalid cache_backend set in the yml config'
end
return @cache
end

def subject
@data = SubjectController.cache_service.retrieve(params[:subject])

respond_to do |f|
renderer_mapping.each do |format, renderer|
f.send(format) do
render :text => renderer.call(@data)
end
end
end

end

def fix_passed_params
#Seems like a double '//' in the captured param is changed to a single one. Unsure of how better to do this...
single_slash_match = params[:subject].match(/^http[s]*\:\/(?!\/)/)
if single_slash_match.present?
params[:subject] = params[:subject][0..single_slash_match[0].length-1] + '/' + params[:subject][single_slash_match[0].length..params[:subject].length]
end
end
end
end
45 changes: 0 additions & 45 deletions app/controllers/subject_controller.rb

This file was deleted.

Loading