Skip to content

Commit

Permalink
Modernize gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jun 26, 2024
1 parent df6100a commit 4562ed8
Show file tree
Hide file tree
Showing 17 changed files with 193 additions and 232 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ root = true
[*]
indent_style = tab
indent_size = 2

[*.{yml,yaml}]
indent_style = space
indent_size = 2
57 changes: 57 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Coverage

on: [push, pull_request]

permissions:
contents: read

env:
CONSOLE_OUTPUT: XTerm
COVERAGE: PartialSummary

jobs:
test:
name: ${{matrix.ruby}} on ${{matrix.os}}
runs-on: ${{matrix.os}}-latest

strategy:
matrix:
os:
- ubuntu
- macos

ruby:
- "3.3"

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{matrix.ruby}}
bundler-cache: true

- name: Run tests
timeout-minutes: 5
run: bundle exec bake test

- uses: actions/upload-artifact@v3
with:
name: coverage-${{matrix.os}}-${{matrix.ruby}}
path: .covered.db

validate:
needs: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true

- uses: actions/download-artifact@v3

- name: Validate coverage
timeout-minutes: 5
run: bundle exec bake covered:validate --paths */.covered.db \;
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
- macos

ruby:
- "2.7"
- "3.0"
- "3.1"
- "3.2"
- "3.3"

experimental: [false]

Expand All @@ -39,7 +39,7 @@ jobs:
experimental: true

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{matrix.ruby}}
Expand Down
13 changes: 3 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
/.bundle/
/.yardoc
/gems.locked
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
.rspec_status
/gems.locked
/.covered.db
/external
3 changes: 0 additions & 3 deletions .rspec

This file was deleted.

7 changes: 7 additions & 0 deletions config/sus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require 'covered/sus'
include Covered::Sus
12 changes: 12 additions & 0 deletions gems.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2017-2024, by Samuel Williams.

source 'https://rubygems.org'

gemspec

group :maintenance, optional: true do
gem "bake-modernize"
gem "bake-gem"

gem "utopia-project"
end

group :test do
gem "sus"
gem "covered"
end
13 changes: 7 additions & 6 deletions guard-falcon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ Gem::Specification.new do |spec|

spec.homepage = "https://github.com/socketry/guard-falcon"

spec.files = Dir.glob('{lib}/**/*', File::FNM_DOTMATCH, base: __dir__)
spec.metadata = {
"source_code_uri" => "https://github.com/socketry/guard-falcon.git",
}

spec.files = Dir.glob(['{lib}/**/*', '*.md'], File::FNM_DOTMATCH, base: __dir__)

spec.required_ruby_version = ">= 3.1"

spec.add_dependency "async-container", "~> 0.16"
spec.add_dependency "console", "~> 1.0"
spec.add_dependency "falcon", "~> 0.35"
spec.add_dependency "guard"
spec.add_dependency "guard-compat", "~> 1.2"

spec.add_development_dependency "bake-bundler"
spec.add_development_dependency "bundler"
spec.add_development_dependency "covered"
spec.add_development_dependency "rspec", "~> 3.6"
end
30 changes: 5 additions & 25 deletions lib/guard/falcon.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2017-2024, by Samuel Williams.

require_relative 'falcon/plugin'

Expand All @@ -25,10 +10,5 @@ module Falcon
def self.new(*arguments, **options)
Plugin.new(*arguments, **options)
end

# Workaround for https://github.com/guard/guard/pull/872
def self.superclass
nil
end
end
end
end
96 changes: 29 additions & 67 deletions lib/guard/falcon/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,86 +1,48 @@
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# frozen_string_literal: true

require 'guard/compat/plugin'

require 'rack/builder'
# Released under the MIT License.
# Copyright, 2017-2024, by Samuel Williams.
# Copyright, 2018-2019, by Huba Nagy.

require 'console/logger'
require 'async/container'
require 'guard/compat/plugin'

require 'falcon/server'
require 'falcon/endpoint'
require 'falcon/controller/serve'
require 'falcon'
require 'falcon/environment/rackup'
require 'falcon/environment/server'
require 'async/service'
require 'console'

module Guard
module Falcon
class Plugin < Guard::Plugin
DEFAULT_OPTIONS = {
config: 'config.ru',
count: 1,
verbose: false,
}
def self.default_environment(**options)
Async::Service::Environment.new(::Falcon::Environment::Server).with(
::Falcon::Environment::Rackup,
**options
)
end

def initialize(**options)
super

@options = DEFAULT_OPTIONS.merge(options)

@endpoint = nil
options[:root] ||= Dir.pwd
options[:name] ||= "falcon"

@controller = ::Falcon::Controller::Serve.new(self)
end

def container_class
Async::Container::Threaded
end

def container_options
{}
end

private def build_endpoint
# Support existing use cases where only port: is specified.
if @options[:endpoint]
return @options[:endpoint]
if paths = options[:paths]
@configuration = Async::Service::Configuration.load(paths)
else
url = @options.fetch(:url, "https://localhost")
port = @options.fetch(:port, 9292)
@configuration = Async::Service::Configuration.new

# Compatibility
if rackup_path = options.delete(:config)
warn "The :config option is deprecated, please use :rackup_path instead.", uplevel: 1
options[:rackup_path] = rackup_path
end

return ::Falcon::Endpoint.parse(url, port: port)
@configuration.add(self.class.default_environment(**options))
end
end

def endpoint
@endpoint ||= build_endpoint
end

def load_app
rack_app, options = Rack::Builder.parse_file(@options[:config])

return ::Falcon::Server.middleware(rack_app, verbose: @options[:verbose])
end

# As discussed in https://github.com/guard/guard/issues/713
def logger
Console.logger
@controller = ::Async::Service::Controller.new(@configuration.services.to_a)
end

def start
Expand Down
23 changes: 4 additions & 19 deletions lib/guard/falcon/version.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2017-2024, by Samuel Williams.

module Guard
module Falcon
Expand Down
23 changes: 23 additions & 0 deletions license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# MIT License

Copyright, 2017-2024, by Samuel Williams.
Copyright, 2018-2019, by Huba Nagy.
Copyright, 2020, by Olle Jonsson.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 4562ed8

Please sign in to comment.