Skip to content

Commit

Permalink
Merge pull request #202 from MXfive/refactor
Browse files Browse the repository at this point in the history
Refactor into one class per file, add Rubocop
  • Loading branch information
cyu committed Mar 22, 2020
2 parents 87efede + 92c77f3 commit dbea904
Show file tree
Hide file tree
Showing 19 changed files with 607 additions and 528 deletions.
31 changes: 31 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---

AllCops:
Exclude:
- 'examples/**/*'

# Disables
Layout/LineLength:
Enabled: false
Style/Documentation:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/BlockLength:
Enabled: false
Style/HashEachMethods:
Enabled: false
Style/HashTransformKeys:
Enabled: false
Style/HashTransformValues:
Enabled: false
Style/DoubleNegation:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Metrics/AbcSize:
Enabled: false
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
language: ruby
sudo: false
rvm:
- 2.2
- 2.3
- 2.4
- 2.5
- 2.6
- 2.7

script:
- bundle exec rubocop
- bundle exec rake test
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in rack-cors.gemspec
Expand Down
9 changes: 5 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "bundler/gem_tasks"
# frozen_string_literal: true

require 'bundler/gem_tasks'

require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
Expand All @@ -7,15 +9,14 @@ Rake::TestTask.new(:test) do |test|
test.verbose = true
end

task :default => :test
task default: :test

require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
version = File.exist?('VERSION') ? File.read('VERSION') : ''

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "rack-cors #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end

4 changes: 2 additions & 2 deletions examples/rack/Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

source "https://rubygems.org"
source 'https://rubygems.org'

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

gem 'rack'
gem 'rack-cors', '>= 1.1.0'
28 changes: 15 additions & 13 deletions examples/rack/config.ru
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
# frozen_string_literal: true

require 'rack/cors'

app = Rack::Builder.app do
use Rack::Cors, :debug => true, :logger => Logger.new(STDOUT) do
use Rack::Cors, debug: true, logger: Logger.new(STDOUT) do
allow do
origins '*'

resource '/cors',
:headers => :any,
:methods => [:post],
:max_age => 0
headers: :any,
methods: [:post],
max_age: 0

resource '*',
:headers => :any,
:methods => [:get, :post, :delete, :put, :patch, :options, :head],
:max_age => 0
headers: :any,
methods: %i[get post delete put patch options head],
max_age: 0
end
end

use Rack::Static, :urls => ["/static.txt"], :root => 'public'
use Rack::Static, urls: ['/static.txt'], root: 'public'

map "/cors" do
map '/cors' do
run lambda { |env|
[
200,
{'Content-Type' => 'text/plain'},
env[Rack::REQUEST_METHOD] == "HEAD" ? [] : ['OK!']
{ 'Content-Type' => 'text/plain' },
env[Rack::REQUEST_METHOD] == 'HEAD' ? [] : ['OK!']
]
}
end

run lambda { |env|
[
200,
{'Content-Type' => 'text/plain'},
env[Rack::REQUEST_METHOD] == "HEAD" ? [] : ["Hello world"]
{ 'Content-Type' => 'text/plain' },
env[Rack::REQUEST_METHOD] == 'HEAD' ? [] : ['Hello world']
]
}
end
Expand Down

0 comments on commit dbea904

Please sign in to comment.