Skip to content

Commit

Permalink
Turn the app into a mountable Rails engine
Browse files Browse the repository at this point in the history
  • Loading branch information
awead committed Oct 2, 2013
1 parent ddfd5cf commit 7f67159
Show file tree
Hide file tree
Showing 93 changed files with 385 additions and 782 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
/tmp
Gemfile.lock
Gemfile.lock
coverage
coverage
pkg
spec/internal
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr

### Submitting Changes

[Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)

* Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
* Make sure your branch is up to date with its parent branch (i.e. master)
* `git checkout master`
Expand Down
55 changes: 5 additions & 50 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,51 +1,6 @@
source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# 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', '~> 1.2'

# For bulk data imports
gem 'activerecord-import', '>= 0.4.0'

group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end

gem 'curb'
gem 'nokogiri', '~> 1.6.0'

group :development, :test do
gem 'rspec'
gem 'rspec-rails'
gem 'debugger'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
end
group :test do
gem 'rspec'
gem 'rspec-rails'
gem 'webmock'
gem 'simplecov', require: false
end
source "https://rubygems.org"

# Declare your gem's dependencies in qa.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
##########################################################################
# Copyright 2013 Rock and Roll Hall of Fame and Museum
# Additional copyright may be held by others, as reflected in the commit log
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
41 changes: 31 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,37 @@ results from a given vocabulary in the JSON format. The controller does three t

### Sub-Authorities

Some authorties, such as Library of Congress, allow sub-authorties which is an additional parameter that
Some authorities, such as Library of Congress, allow sub-authorities which is an additional parameter that
further defines the kind of authority to use with the context of a larger one.

## How do use this?

Add the gem to your Gemfile

gem 'qa'

Add the engine to your config/routes.rb file

mount Qa::Engine => '/qa'

Start questioning your authorities!

### Examples

Return a complete list of terms:

/terms/:vocab
/terms/:vocab/:sub_authority
/qa/terms/:vocab
/qa/terms/:vocab/:sub_authority

Return a set of terms matching a given query

/search/:vocab?q=search_term
/search/:vocab/:sub_authority?q=search_term
/qa/search/:vocab?q=search_term
/qa/search/:vocab/:sub_authority?q=search_term

Return the complete information for a specific term given its identifier

/show/:vocab/:id
/show/:vocab/:sub_authority/:id
/qa/show/:vocab/:id
/qa/show/:vocab/:sub_authority/:id

### JSON Results

Expand All @@ -55,7 +67,7 @@ Results are returned in JSON in this format:

Results for specific terms may vary according to the term. For example:

/show/mesh/D000001
/qa/show/mesh/D000001

Might return:

Expand All @@ -65,7 +77,7 @@ Might return:
"synonyms" : ["A-23187", "A23187", "Antibiotic A23187", "A 23187", "A23187, Antibiotic"]
}

This is due to the varing nature of each authority source. However, results for multiple terms, such as a search, we
This is due to the varying nature of each authority source. However, results for multiple terms, such as a search, we
should always use the above id and label structure to ensure interoperability at the GUI level.

# Authority Sources information
Expand Down Expand Up @@ -131,11 +143,20 @@ This may take a few minutes to finish.

# TODOs

* Make this an engine
* Provide show method to TermsController to return individual terms

check the issue list for more...

# Developer Notes

To develop this gem, clone the repository, then run:

bundle install
rake

This will install the gems, create a dummy application under spec/internal and run the tests. After you've made changes, remove the entire spec/internal
directory so that further tests and run against a new dummy application.

# Authors

* Stephen Anderson
Expand Down
12 changes: 8 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# 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.
#!/usr/bin/env rake
require "bundler/gem_tasks"

require File.expand_path('../config/application', __FILE__)
Dir.glob('tasks/*.rake').each { |r| import r }

QuestioningAuthority::Application.load_tasks
ENV["RAILS_ROOT"] ||= 'spec/internal'

require 'rspec/core/rake_task'

task :default => [:spec]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,4 @@
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
File renamed without changes.
5 changes: 0 additions & 5 deletions app/controllers/application_controller.rb

This file was deleted.

Empty file removed app/controllers/concerns/.keep
Empty file.
4 changes: 4 additions & 0 deletions app/controllers/qa/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Qa
class ApplicationController < ActionController::Base
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# which class to instantiate based on the "vocab" param. All the authotirty classes inherit from a
# super class so they implement the same methods.

class TermsController < ApplicationController
class Qa::TermsController < ApplicationController

before_action :check_search_params, only:[:search]
before_action :check_vocab_param, :check_authority, :check_sub_authority
Expand Down Expand Up @@ -70,7 +70,7 @@ def check_sub_authority
private

def authority_class
"Authorities::"+params[:vocab].capitalize
"Qa::Authorities::"+params[:vocab].capitalize
end

end
2 changes: 0 additions & 2 deletions app/helpers/application_helper.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/helpers/qa/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Qa::ApplicationHelper
end
Empty file removed app/mailers/.keep
Empty file.
Empty file removed app/models/.keep
Empty file.
Empty file removed app/models/concerns/.keep
Empty file.
2 changes: 1 addition & 1 deletion app/models/mesh_tree.rb → app/models/qa/mesh_tree.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class MeshTree < ActiveRecord::Base
class Qa::MeshTree < ActiveRecord::Base
belongs_to :subject_mesh_term , :foreign_key => "term_id"

def self.classify_all_trees
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class SubjectMeshTerm < ActiveRecord::Base
class Qa::SubjectMeshTerm < ActiveRecord::Base
has_many :mesh_trees, :foreign_key => "term_id"

def self.from_tree_number(tree_id)
SubjectMeshTerm.joins('INNER JOIN mesh_trees ON subject_mesh_terms.term_id = mesh_trees.term_id').where('mesh_trees.tree_number = ?', tree_id)
Qa::SubjectMeshTerm.joins('INNER JOIN qa_mesh_trees ON qa_subject_mesh_terms.term_id = qa_mesh_trees.term_id').where('qa_mesh_trees.tree_number = ?', tree_id)
end

def trees
MeshTree.where(term_id: self.term_id).map { |t| t.tree_number }
Qa::MeshTree.where(term_id: self.term_id).map { |t| t.tree_number }
end

def synonyms
Expand All @@ -25,7 +25,7 @@ def synonyms=(syn_list)

def parents
t = self.trees
t.map { |tn| initial_segements_of(tn) }.flatten.uniq.map { |tn| SubjectMeshTerm.from_tree_number(tn) }
t.map { |tn| initial_segements_of(tn) }.flatten.uniq.map { |tn| Qa::SubjectMeshTerm.from_tree_number(tn) }
end

private
Expand Down
14 changes: 0 additions & 14 deletions app/views/layouts/application.html.erb

This file was deleted.

14 changes: 14 additions & 0 deletions app/views/layouts/qa/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Qa</title>
<%= stylesheet_link_tag "qa/application", media: "all" %>
<%= javascript_include_tag "qa/application" %>
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>
3 changes: 0 additions & 3 deletions bin/bundle

This file was deleted.

4 changes: 0 additions & 4 deletions bin/rails

This file was deleted.

4 changes: 0 additions & 4 deletions bin/rake

This file was deleted.

4 changes: 0 additions & 4 deletions config.ru

This file was deleted.

24 changes: 0 additions & 24 deletions config/application.rb

This file was deleted.

4 changes: 0 additions & 4 deletions config/boot.rb

This file was deleted.

25 changes: 0 additions & 25 deletions config/database.yml

This file was deleted.

5 changes: 0 additions & 5 deletions config/environment.rb

This file was deleted.

Loading

0 comments on commit 7f67159

Please sign in to comment.