Skip to content

Commit

Permalink
Appease standardrb
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Kaffenberger committed Jul 22, 2024
1 parent e9d7bcf commit 7b533eb
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 86 deletions.
3 changes: 1 addition & 2 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
ignore: # default: []
- 'test/sample/node_modules/**/*'
ruby_version: 2.7
14 changes: 7 additions & 7 deletions gemfiles/rails_6.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gem 'rails', '~> 6.0.0'
gem "rails", "~> 6.0.0"

group :development, :test do
gem 'guard', require: false
gem 'guard-minitest', require: false
gem 'pry'
gem 'pry-byebug', platforms: [:mri]
gem "guard", require: false
gem "guard-minitest", require: false
gem "pry"
gem "pry-byebug", platforms: [:mri]
end

gemspec path: '../'
gemspec path: "../"
14 changes: 7 additions & 7 deletions gemfiles/rails_6.1.gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gem 'rails', '~> 6.1.0'
gem "rails", "~> 6.1.0"

group :development, :test do
gem 'guard', require: false
gem 'guard-minitest', require: false
gem 'pry'
gem 'pry-byebug', platforms: [:mri]
gem "guard", require: false
gem "guard-minitest", require: false
gem "pry"
gem "pry-byebug", platforms: [:mri]
end

gemspec path: '../'
gemspec path: "../"
14 changes: 7 additions & 7 deletions gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gem 'rails', '~> 7.0.0'
gem "rails", "~> 7.0.0"

group :development, :test do
gem 'guard', require: false
gem 'guard-minitest', require: false
gem 'pry'
gem 'pry-byebug', platforms: [:mri]
gem "guard", require: false
gem "guard-minitest", require: false
gem "pry"
gem "pry-byebug", platforms: [:mri]
end

gemspec path: '../'
gemspec path: "../"
14 changes: 7 additions & 7 deletions gemfiles/rails_7.1.gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gem 'rails', '~> 7.1.0'
gem "rails", "~> 7.1.0"

group :development, :test do
gem 'guard', require: false
gem 'guard-minitest', require: false
gem 'pry'
gem 'pry-byebug', platforms: [:mri]
gem "guard", require: false
gem "guard-minitest", require: false
gem "pry"
gem "pry-byebug", platforms: [:mri]
end

gemspec path: '../'
gemspec path: "../"
2 changes: 1 addition & 1 deletion lib/serviceworker/handlers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def ===(other)
def handler_for_name(name)
available_handlers = %w[sprockets webpacker rack]
if available_handlers.include?(name.to_s)
send("#{name}_handler")
send(:"#{name}_handler")
else
raise ServiceWorker::Error,
"Unknown handler #{name.inspect}. Please use one of #{available_handlers.inspect}"
Expand Down
10 changes: 5 additions & 5 deletions lib/serviceworker/handlers/webpacker_handler.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require 'rack/file'
require "rack/file"
begin
require 'webpacker'
require "webpacker"
rescue LoadError
# ignore
end
Expand All @@ -11,15 +11,15 @@ module ServiceWorker
module Handlers
class WebpackerHandler
def call(env)
path_info = env.fetch('serviceworker.asset_name')
path_info = env.fetch("serviceworker.asset_name")

path = Webpacker.manifest.lookup(path_info)

if Webpacker.dev_server.running?
proxy = Webpacker::DevServerProxy.new
proxy.call(env.merge('PATH_INFO' => path))
proxy.call(env.merge("PATH_INFO" => path))
else
file_server.call(env.merge('PATH_INFO' => path))
file_server.call(env.merge("PATH_INFO" => path))
end
end

Expand Down
16 changes: 8 additions & 8 deletions lib/serviceworker/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ module ServiceWorker
class Route
attr_reader :path_pattern, :asset_pattern, :options

RouteMatch = Struct.new(:path, :asset_name, :headers, :options) {
RouteMatch = Struct.new(:path, :asset_name, :headers, :options) do
def to_s
asset_name
end
}
end

def self.webpacker?(options)
options.key?(:pack) && Handlers.webpacker?
Expand Down Expand Up @@ -54,9 +54,9 @@ def resolver
class AssetResolver
PATH_INFO = "PATH_INFO"
DEFAULT_WILDCARD_NAME = :paths
WILDCARD_PATTERN = %r{/\*([^/]*)}.freeze
NAMED_SEGMENTS_PATTERN = %r{/([^/]*):([^:$/]+)}.freeze
LEADING_SLASH_PATTERN = %r{^/}.freeze
WILDCARD_PATTERN = %r{/\*([^/]*)}
NAMED_SEGMENTS_PATTERN = %r{/([^/]*):([^:$/]+)}
LEADING_SLASH_PATTERN = %r{^/}
INTERPOLATION_PATTERN = Regexp.union(
/%%/,
/%\{(\w+)\}/ # matches placeholders like "%{foo}"
Expand Down Expand Up @@ -112,14 +112,14 @@ def path_captures(regexp, path)
params = if @wildcard_name
{@wildcard_name => path_match[1].to_s.split("/")}
else
Hash[path_match.names.map(&:to_sym).zip(path_match.captures)]
path_match.names.map(&:to_sym).zip(path_match.captures).to_h
end
params.delete(:format) if params.key?(:format) && params[:format].nil?
params
end

def interpolate_captures(string, captures)
string.gsub(INTERPOLATION_PATTERN) { |match|
string.gsub(INTERPOLATION_PATTERN) do |match|
if match == "%%"
"%"
else
Expand All @@ -128,7 +128,7 @@ def interpolate_captures(string, captures)
value = value.call(captures) if value.respond_to?(:call)
Regexp.last_match(3) ? format("%#{Regexp.last_match(3)}", value) : value
end
}.gsub(LEADING_SLASH_PATTERN, "")
end.gsub(LEADING_SLASH_PATTERN, "")
end
end
end
Expand Down
40 changes: 20 additions & 20 deletions serviceworker-rails.gemspec
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'serviceworker/rails/version'
require "serviceworker/rails/version"

Gem::Specification.new do |spec|
spec.name = 'serviceworker-rails'
spec.name = "serviceworker-rails"
spec.version = ServiceWorker::Rails::VERSION
spec.authors = ['Ross Kaffenberger']
spec.email = ['[email protected]']
spec.authors = ["Ross Kaffenberger"]
spec.email = ["[email protected]"]

spec.summary = 'ServiceWorker for Rails 5+'
spec.description = 'Integrates ServiceWorker into the Rails asset pipeline.'
spec.homepage = 'https://github.com/rossta/serviceworker-rails'
spec.license = 'MIT'
spec.summary = "ServiceWorker for Rails 5+"
spec.description = "Integrates ServiceWorker into the Rails asset pipeline."
spec.homepage = "https://github.com/rossta/serviceworker-rails"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = 'exe'
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.require_paths = ["lib"]

spec.add_dependency 'railties', '>= 6.0'
spec.add_dependency "railties", ">= 6.0"

spec.add_development_dependency 'minitest', '~> 5.0'
spec.add_development_dependency 'rack-test'
spec.add_development_dependency 'rails'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'sprockets', '~> 3.0'
spec.add_development_dependency 'sprockets-rails'
spec.add_development_dependency 'standard'
spec.add_development_dependency "minitest", "~> 5.0"
spec.add_development_dependency "rack-test"
spec.add_development_dependency "rails"
spec.add_development_dependency "rake"
spec.add_development_dependency "simplecov"
spec.add_development_dependency "sprockets", "~> 3.0"
spec.add_development_dependency "sprockets-rails"
spec.add_development_dependency "standard"
end
2 changes: 1 addition & 1 deletion test/sample/config/initializers/serviceworker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

config.serviceworker.routes.draw do
match "/header-serviceworker.js" => "another/serviceworker.js",
:headers => {"X-Resource-Header" => "A resource"}
:headers => {"X-Resource-Header" => "A resource"}

match "/nested/serviceworker.js", asset: "another/serviceworker.js"

Expand Down
2 changes: 1 addition & 1 deletion test/serviceworker/rack_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def router
ServiceWorker::Router.new do
match "/serviceworker.js" => "assets/serviceworker.js"
match "/cacheable-serviceworker.js" => "assets/serviceworker.js",
:headers => {"Cache-Control" => "public, max-age=12345"}
:headers => {"Cache-Control" => "public, max-age=12345"}
end
end

Expand Down
40 changes: 20 additions & 20 deletions test/serviceworker/route_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,38 @@ def test_initialize_route_with_asset

def test_match
match "/*", "foo", "/", "foo"
match "/*", "%{paths}", "/", ""
match "/*", "%<paths>s", "/", ""
match "/*", "foo", "/foo", "foo"
match "/*", "%{paths}", "/foo", "foo"
match "/*", "%<paths>s", "/foo", "foo"
match "/*", "foo", "/foo/bar/baz", "foo"
match "/*", "%{paths}", "/foo/bar/baz", "foo/bar/baz"
match "/*", "%<paths>s", "/foo/bar/baz", "foo/bar/baz"
match "/*/foobar.js", "foobar.js", "/not/found/foo/bar.js", nil
match "/*/foobar.js", "foobar.js", "/is/found/foobar.js", "foobar.js"

match "/*stuff", "foo", "/", "foo"
match "/*stuff", "%{stuff}/foo", "/", "foo"
match "/*stuff", "%{stuff}/bar", "/foo", "foo/bar"
match "/*stuff", "%{stuff}/bar", "/foo/", "foo/bar"
match "/*stuff", "%{stuff}/boo", "/foo/bar/baz", "foo/bar/baz/boo"

match "/foo/*", "%{paths}", "/foo", ""
match "/foo/*", "%{paths}", "/foo/bar", "bar"
match "/foo/*", "%{paths}", "/foo/bar/baz", "bar/baz"
match "/foo/*stuff", "%{stuff}", "/", nil
match "/foo/*stuff", "%{stuff}", "/foo", ""
match "/foo/*stuff", "%{stuff}", "/foo/bar/baz", "bar/baz"
match "/*stuff", "%<stuff>s/foo", "/", "foo"
match "/*stuff", "%<stuff>s/bar", "/foo", "foo/bar"
match "/*stuff", "%<stuff>s/bar", "/foo/", "foo/bar"
match "/*stuff", "%<stuff>s/boo", "/foo/bar/baz", "foo/bar/baz/boo"

match "/foo/*", "%<paths>s", "/foo", ""
match "/foo/*", "%<paths>s", "/foo/bar", "bar"
match "/foo/*", "%<paths>s", "/foo/bar/baz", "bar/baz"
match "/foo/*stuff", "%<stuff>s", "/", nil
match "/foo/*stuff", "%<stuff>s", "/foo", ""
match "/foo/*stuff", "%<stuff>s", "/foo/bar/baz", "bar/baz"
match "/", "", "/", ""
match "/", "", "/foo", nil
match "/foo", "", "/", nil
match "/foo", "", "/foo", ""
match "/:id", nil, "/42", ":id"
match "/:id", nil, "/", nil
match "/posts/:id", "%{id}", "/posts/42", "42"
match "/posts/:id", "%{id}", "/posts", nil
match "/:x/:y", "%{x}/%{y}", "/a/b", "a/b"
match "/posts/:id", "%{id}.js", "/posts/42.js", "42.js"
match "/api/v:version", "%{version}", "/api/v2", "2"
match "/api/v:version/things", "%{version}", "/api/v2/things", "2"
match "/posts/:id", "%<id>s", "/posts/42", "42"
match "/posts/:id", "%<id>s", "/posts", nil
match "/:x/:y", "%<x>s/%<y>s", "/a/b", "a/b"
match "/posts/:id", "%<id>s.js", "/posts/42.js", "42.js"
match "/api/v:version", "%<version>s", "/api/v2", "2"
match "/api/v:version/things", "%<version>s", "/api/v2/things", "2"
end

def test_match_route_pack_true
Expand Down

0 comments on commit 7b533eb

Please sign in to comment.