Skip to content
This repository has been archived by the owner on Nov 13, 2022. It is now read-only.

Small code cleanup / update (WIP) #17

Open
wants to merge 2 commits 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
13 changes: 13 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
AllCops:
DisplayCopNames: true
Exclude:
- Gemfile
- ./*.gemspec
- ./bin/**/*
- ./test/**/*

Style/Documentation:
Enabled: false

Lint/Debugger:
Enabled: false
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.4.0
15 changes: 3 additions & 12 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
source "https://rubygems.org"
# frozen_string_literal: true

# Declare your gem's dependencies in swagger_engine.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
source 'https://rubygems.org'

# To use debugger
# gem 'debugger'
gemspec
24 changes: 23 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,34 @@ PATH
GEM
remote: https://rubygems.org/
specs:
ast (2.3.0)
coderay (1.1.1)
method_source (0.8.2)
parser (2.4.0.0)
ast (~> 2.2)
powerpack (0.1.1)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rainbow (2.2.1)
rubocop (0.48.1)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
slop (3.6.0)
unicode-display_width (1.2.1)

PLATFORMS
ruby

DEPENDENCIES
pry
rubocop
swagger_engine!

BUNDLED WITH
1.11.2
1.14.6
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# LOOKING FOR MAINTAINER

I'm sorry but I can't maintain this project anymore.

If you want to maintain this project, contact me (batdevis[at]gmail.com) and I will transfer the ownership.

# SwaggerEngine

Include [swagger-ui](https://github.com/swagger-api/swagger-ui) as rails engine.
Include [swagger-ui](https://github.com/swagger-api/swagger-ui) as Rails engine.

## Swagger specifications

Expand Down Expand Up @@ -40,7 +34,7 @@ authenticate :user, lambda { |u| u.admin? } do
end
```

#### Basic http auth
#### Basic HTTP Auth

Set username and password in `config/initializers/swagger_engine.rb`:

Expand All @@ -53,7 +47,7 @@ end

## Configure

### Json files
### JSON files

Set the path of your json files in a initializer:

Expand All @@ -69,9 +63,9 @@ end
```
`lib/swagger/` is a good place to place them..

### Edit your json files
### Edit your JSON files

Use [Swagger editor](https://github.com/swagger-api/swagger-editor).
Use [Swagger Editor](https://github.com/swagger-api/swagger-editor).

## License

Expand All @@ -81,4 +75,4 @@ This project rocks and uses MIT-LICENSE.

[Rawfish](http://rawfishindustries.com)

[![Rawfish Logo](http://rawfishindustries.com/wp-content/uploads/2015/03/logo_rawfish_WEB.jpg)](http://rawfishindustries.com)
[![Rawfish Logo](http://rawfishindustries.com/wp-content/uploads/2016/07/rawfish-logo-black.png)](http://rawfishindustries.com)
6 changes: 2 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

begin
require 'bundler/setup'
rescue LoadError
Expand All @@ -14,9 +16,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb')
end




Bundler::GemHelper.install_tasks

require 'rake/testtask'
Expand All @@ -28,5 +27,4 @@ Rake::TestTask.new(:test) do |t|
t.verbose = false
end


task default: :test
14 changes: 8 additions & 6 deletions app/controllers/swagger_engine/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# frozen_string_literal: true

module SwaggerEngine
class ApplicationController < ActionController::Base

before_filter :authenticate

protected

def authenticate
if SwaggerEngine.configuration.admin_username
authenticate_or_request_with_http_basic do |username, password|
username == SwaggerEngine.configuration.admin_username && password == SwaggerEngine.configuration.admin_password
end
return unless SwaggerEngine.configuration.admin_username

authenticate_or_request_with_http_basic do |username, password|
username == SwaggerEngine.configuration.admin_username \
&& password == SwaggerEngine.configuration.admin_password
end
end

end
end
31 changes: 22 additions & 9 deletions app/controllers/swagger_engine/swaggers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require_dependency "swagger_engine/application_controller"
# frozen_string_literal: true

require_dependency 'swagger_engine/application_controller'

module SwaggerEngine
class SwaggersController < ApplicationController
Expand All @@ -7,23 +9,34 @@ class SwaggersController < ApplicationController
before_filter :load_json_files

def index
redirect_to swagger_path(@json_files.first[0]) if ( @json_files.size == 1 )
redirect_to swagger_path(@json_files.first[0]) if @json_files.size == 1
end

def show
respond_to do |format|
format.html {
@swagger_json_url = swagger_path(params[:id], format: :json)
}
format.json {
send_file @json_files[params[:id].to_sym], type: 'application/json', disposition: 'inline'
}
format.html { show_html }
format.json { show_json }
end
end

private

def show_html
@swagger_json_url = swagger_path(params[:id], format: :json)
end

def show_json
send_file(
@json_files[params[:id].to_sym],
type: 'application/json',
disposition: 'inline'
)
end

def load_json_files
@json_files ||= SwaggerEngine.configuration.json_files || { default: "#{Rails.root}/lib/swagger_engine/swagger.json" }
@json_files ||= SwaggerEngine.configuration.json_files || {
default: "#{Rails.root}/lib/swagger_engine/swagger.json"
}
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/swagger_engine/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SwaggerEngine
module ApplicationHelper
end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/swagger_engine/swagger_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SwaggerEngine
module SwaggerHelper
end
Expand Down
2 changes: 2 additions & 0 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.

ENGINE_ROOT = File.expand_path('../..', __FILE__)
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true

SwaggerEngine::Engine.routes.draw do
resources :swaggers, only: [:index, :show]
resources :swaggers, only: %i[index show]
root to: 'swaggers#index'
end
4 changes: 3 additions & 1 deletion lib/swagger_engine.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "swagger_engine/engine"
# frozen_string_literal: true

require 'swagger_engine/engine'

module SwaggerEngine
end
19 changes: 9 additions & 10 deletions lib/swagger_engine/engine.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
# frozen_string_literal: true

module SwaggerEngine
class Engine < ::Rails::Engine
isolate_namespace SwaggerEngine

#https://gist.github.com/parndt/11381872
=begin
initializer "swagger_engine.assets.precompile", group: :all do |app|
app.config.assets.precompile += ['swagger_engine/print.css', 'swagger_engine/reset.css']
end
=end
# https://gist.github.com/parndt/11381872
config.to_prepare do
Rails.application.config.assets.precompile += ['swagger_engine/print.css', 'swagger_engine/reset.css']
Rails.application.config.assets.precompile += %w[
swagger_engine/print.css swagger_engine/reset.css
]
end

end

class Configuration
#[{ default: "swagger.json" }]
# [{ default: "swagger.json" }]
attr_accessor :json_files
attr_accessor :admin_username
attr_accessor :admin_password
Expand All @@ -25,11 +23,12 @@ class << self
end

module_function

def configuration
@configuration ||= Configuration.new
end

def configure
yield(configuration)
end
end
end
4 changes: 3 additions & 1 deletion lib/swagger_engine/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SwaggerEngine
VERSION = "0.0.3"
VERSION = '0.0.3'
end
1 change: 1 addition & 0 deletions lib/tasks/swagger_engine_tasks.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# desc "Explaining what the task does"
# task :swagger_engine do
# # Task goes here
Expand Down
27 changes: 16 additions & 11 deletions swagger_engine.gemspec
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
$:.push File.expand_path("../lib", __FILE__)
# frozen_string_literal: true

$LOAD_PATH.push File.expand_path('../lib', __FILE__)

# Maintain your gem's version:
require "swagger_engine/version"
require 'swagger_engine/version'

# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "swagger_engine"
s.name = 'swagger_engine'
s.version = SwaggerEngine::VERSION
s.authors = ["batdevis"]
s.email = ["[email protected]"]
s.homepage = "https://github.com/batdevis/swagger_engine"
s.summary = "Mount swagger-ui as rails engine."
s.description = "Api docs inside your rails project."
s.license = "MIT"
s.authors = ['batdevis']
s.email = ['[email protected]']
s.homepage = 'https://github.com/batdevis/swagger_engine'
s.summary = 'Mount swagger-ui as rails engine.'
s.description = 'Api docs inside your rails project.'
s.license = 'MIT'

s.add_development_dependency('pry')
s.add_development_dependency('rubocop')

s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.rdoc']
s.test_files = Dir['test/**/*']
end
2 changes: 2 additions & 0 deletions test/controllers/swagger_engine/swagger_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'

module SwaggerEngine
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# 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.

Expand Down
2 changes: 2 additions & 0 deletions test/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module ApplicationHelper
end
2 changes: 2 additions & 0 deletions test/dummy/bin/bundle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
4 changes: 3 additions & 1 deletion test/dummy/bin/rails
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
# frozen_string_literal: true

APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
2 changes: 2 additions & 0 deletions test/dummy/bin/rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require_relative '../config/boot'
require 'rake'
Rake.application.run
4 changes: 3 additions & 1 deletion test/dummy/config.ru
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true

# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
Loading