rails-pwa 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d8581d3545b70371f9fe94f866bb8e56b49b3045358e27c9b63e54ee84e1c803
4
+ data.tar.gz: a1909235a41e830701e06aa1c4df72ed51ea099e8b7d354be39a907aa03fc8cf
5
+ SHA512:
6
+ metadata.gz: 8aa9c5da1c29ffb37ef21e566533e8611075102e1678a9358549d952647da3cca90c0cf30799de33085418438346220da7e47ccc7591448cf050fe67f1b306bf
7
+ data.tar.gz: 17363f16ec7a6d64d4cfcbad5246a3e208b5a2c92c09f825139f64c4de94062945ee8664fef596b7302e8c90708537d044f933a37463dbc2cd0ff3790b12ef90
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 Tom Ward
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Rails::Pwa
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'rails-pwa'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install rails-pwa
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Rails::Pwa'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,38 @@
1
+ module Rails
2
+ module PWA
3
+ class Interceptor
4
+ attr_reader :app, :server, :scripts
5
+
6
+ def initialize(app, options = {})
7
+ @app = app
8
+ @server = ::Rack::File.new(Rails.root + "public")
9
+ @scripts = { "/worker.js" => "worker.js" }
10
+ end
11
+
12
+ def call(env)
13
+ if pack = scripts[env["PATH_INFO"]]
14
+ respond_with_pack(env, pack)
15
+ else
16
+ app.call(env)
17
+ end
18
+ end
19
+
20
+ def respond_with_pack(env, pack)
21
+ path_info = env["PATH_INFO"]
22
+ env["PATH_INFO"] = Webpacker.manifest.lookup!(pack)
23
+
24
+ if respond_directly?
25
+ server.call(env)
26
+ else
27
+ app.call(env)
28
+ end
29
+ ensure
30
+ env["PATH_INFO"] = path_info
31
+ end
32
+
33
+ def respond_directly?
34
+ !Rails.env.development?
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails/pwa/interceptor'
2
+
3
+ class Rails::PWA::Railtie < ::Rails::Railtie
4
+ initializer "rails-pwa.middleware" do |app|
5
+ app.config.app_middleware.use Rails::PWA::Interceptor
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Rails
2
+ module PWA
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
data/lib/rails/pwa.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "rails/pwa/railtie"
2
+
3
+ module Rails
4
+ module Pwa
5
+ # Your code goes here...
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-pwa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom Ward
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 6.0.0.rc1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 6.0.0.rc1
27
+ description: Serves service worker scripts
28
+ email:
29
+ - tom@popdog.net
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/rails/pwa.rb
38
+ - lib/rails/pwa/interceptor.rb
39
+ - lib/rails/pwa/railtie.rb
40
+ - lib/rails/pwa/version.rb
41
+ homepage: https://github.com/tomafro/rails-pwa
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.0.3
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Serve service worker scripts from /worker.js
64
+ test_files: []