canvas-embed 0.1.4 → 0.1.6
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 +4 -4
- data/Gemfile +5 -5
- data/Gemfile.lock +3 -3
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +0 -12
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/canvas-embed.gemspec +15 -14
- data/example/Gemfile +20 -19
- data/example/Gemfile.lock +2 -2
- data/example/README.md +16 -3
- data/example/Rakefile +3 -1
- data/example/app/controllers/application_controller.rb +7 -5
- data/example/bin/bundle +22 -18
- data/example/bin/importmap +3 -2
- data/example/bin/rails +5 -3
- data/example/bin/rake +4 -2
- data/example/bin/setup +10 -8
- data/example/config/application.rb +5 -3
- data/example/config/boot.rb +5 -3
- data/example/config/environment.rb +3 -1
- data/example/config/environments/development.rb +5 -3
- data/example/config/initializers/cors.rb +10 -8
- data/example/config/puma.rb +11 -9
- data/example/config/routes.rb +4 -2
- data/example/config.ru +3 -1
- data/example/log/development.log +188 -2565
- data/example/storage/development.sqlite3-shm +0 -0
- data/example/storage/development.sqlite3-wal +0 -0
- data/example/tmp/cache/bootsnap/compile-cache-iseq/01/2f863f8d7ff70d +0 -0
- data/example/tmp/cache/bootsnap/compile-cache-iseq/0a/707c6e76401f50 +0 -0
- data/example/tmp/cache/bootsnap/compile-cache-iseq/24/4134f174d68291 +0 -0
- data/example/tmp/cache/bootsnap/compile-cache-iseq/3b/64ba0c52596b87 +0 -0
- data/example/tmp/cache/bootsnap/compile-cache-iseq/4c/837c8a08879a20 +0 -0
- data/example/tmp/cache/bootsnap/compile-cache-iseq/68/a73620fd7d4284 +0 -0
- data/example/tmp/cache/bootsnap/compile-cache-iseq/79/1a2ebed1814cfa +0 -0
- data/example/tmp/cache/bootsnap/compile-cache-iseq/b2/d451a148d6d303 +0 -0
- data/example/tmp/cache/bootsnap/compile-cache-iseq/d8/fff5874ac0039e +0 -0
- data/example/tmp/cache/bootsnap/compile-cache-iseq/ee/02ad963145723a +0 -0
- data/example/tmp/cache/bootsnap/compile-cache-iseq/fb/4f5abf058e6979 +0 -0
- data/example/tmp/cache/bootsnap/load-path-cache +0 -0
- data/example/tmp/pids/server.pid +1 -0
- data/lib/canvas/embed/version.rb +1 -1
- data/lib/canvas/embed.rb +26 -10
- data/pkg/canvas-embed-0.1.5.gem +0 -0
- data/spec/canvas/embed_spec.rb +44 -7
- data/spec/spec_helper.rb +2 -2
- metadata +17 -4
- data/pkg/canvas-embed-0.1.2.gem +0 -0
- data/pkg/canvas-embed-0.1.3.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ed39f8027511445d28514cde191bade34d5b4101814dfb4bd7307d5b7eb51e4
|
4
|
+
data.tar.gz: 7528eaaf4db9c5c77d3be5a6a50ba40eb1321e9805b119b3144300ea020cd861
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a277e1fe0976095609dea6a27e35101028eeec6c8cb0129e05b91a61c8b40eab15c8a445189c9219915355d58722f6cdce6d4ae0998bfb80bf2158a1d1fd0580
|
7
|
+
data.tar.gz: edacd70f37ed8c97e9a4a045c795e5608ad967bf088cd5b9e6818a00be9889dbbb451eb5f422c0bd5fae1ab120331ea442b77533804867475109d06d8654c833
|
data/Gemfile
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
3
|
+
source 'https://rubygems.org'
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in canvas-embed.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem
|
8
|
+
gem 'rake', '~> 13.1'
|
9
9
|
|
10
|
-
gem
|
10
|
+
gem 'rspec', '~> 3.0'
|
11
11
|
|
12
|
-
gem
|
12
|
+
gem 'rubocop', '~> 1.21'
|
13
13
|
|
14
|
-
gem
|
14
|
+
gem 'rbnacl', '~> 7.1.1'
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
canvas-embed (0.1.
|
4
|
+
canvas-embed (0.1.4)
|
5
5
|
rbnacl (~> 7.1.1)
|
6
6
|
|
7
7
|
GEM
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
racc
|
20
20
|
racc (1.7.1)
|
21
21
|
rainbow (3.1.1)
|
22
|
-
rake (13.0
|
22
|
+
rake (13.1.0)
|
23
23
|
rbnacl (7.1.1)
|
24
24
|
ffi
|
25
25
|
regexp_parser (2.8.2)
|
@@ -59,7 +59,7 @@ PLATFORMS
|
|
59
59
|
|
60
60
|
DEPENDENCIES
|
61
61
|
canvas-embed!
|
62
|
-
rake (~> 13.
|
62
|
+
rake (~> 13.1)
|
63
63
|
rbnacl (~> 7.1.1)
|
64
64
|
rspec (~> 3.0)
|
65
65
|
rubocop (~> 1.21)
|
data/{LICENSE.txt → LICENSE}
RENAMED
data/README.md
CHANGED
@@ -10,18 +10,6 @@ If any scopes are required by your charts that are not present in the scopes pay
|
|
10
10
|
|
11
11
|
You can view how this Gem is used in a sample rails app in the `example/` directory
|
12
12
|
|
13
|
-
# Running
|
14
|
-
|
15
|
-
```
|
16
|
-
bin/rails server
|
17
|
-
```
|
18
|
-
|
19
|
-
This application expects the key in the CANVAS_SIGNING_KEY variable. You can set this by running:
|
20
|
-
|
21
|
-
```
|
22
|
-
CANVAS_SIGNING_KEY=emk_HgwRqhyt.f0533f95ed220910218667124cac2116fsse11daf2aa1ff9938f7fde7a16c203 bin/rails server
|
23
|
-
```
|
24
|
-
|
25
13
|
# Running tests
|
26
14
|
|
27
15
|
```
|
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
5
|
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
7
|
|
8
|
-
require
|
8
|
+
require 'rubocop/rake_task'
|
9
9
|
|
10
10
|
RuboCop::RakeTask.new
|
11
11
|
|
data/bin/console
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'canvas/embed'
|
6
6
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
9
9
|
|
10
|
-
require
|
10
|
+
require 'irb'
|
11
11
|
IRB.start(__FILE__)
|
data/canvas-embed.gemspec
CHANGED
@@ -1,28 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative 'lib/canvas/embed/version'
|
4
4
|
require 'rake/file_list'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'canvas-embed'
|
8
8
|
spec.version = Canvas::Embed::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Will Pride']
|
10
|
+
spec.email = ['will@canvasapp.com']
|
11
11
|
|
12
|
-
spec.summary =
|
12
|
+
spec.summary = 'Generate tokens to display your Canvas charts in your application.'
|
13
13
|
spec.description = "This Gem allows you to generated signed tokens that grant your users scoped access to your Canvas embeds. This token can be used in Canvas' React component to display your Canvas charts in your own application."
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
16
|
-
spec.required_ruby_version =
|
14
|
+
spec.homepage = 'https://github.com/canvas/embeds'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
spec.required_ruby_version = '>= 2.6.0'
|
17
17
|
|
18
|
-
spec.metadata[
|
19
|
-
spec.metadata[
|
18
|
+
spec.metadata['homepage_uri'] = 'https://canvasapp.com'
|
19
|
+
spec.metadata['source_code_uri'] = 'https://github.com/canvas/embeds'
|
20
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/canvas/embeds/issues'
|
20
21
|
|
21
22
|
spec.files = Rake::FileList['**/*'].exclude(*File.read('.gitignore').split)
|
22
|
-
spec.require_paths = [
|
23
|
+
spec.require_paths = ['lib']
|
23
24
|
|
24
|
-
spec.add_dependency
|
25
|
+
spec.add_dependency 'rbnacl', '~> 7.1.1'
|
25
26
|
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'rubocop', '~> 1.21'
|
28
29
|
end
|
data/example/Gemfile
CHANGED
@@ -1,37 +1,39 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
ruby '3.2.2'
|
4
6
|
|
5
7
|
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
|
6
|
-
gem
|
8
|
+
gem 'rails', '~> 7.1.1'
|
7
9
|
|
8
|
-
gem
|
10
|
+
gem 'canvas-embed', '~> 0.1.4'
|
9
11
|
|
10
12
|
gem 'rack-cors'
|
11
13
|
|
12
14
|
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
|
13
|
-
gem
|
15
|
+
gem 'sprockets-rails'
|
14
16
|
|
15
17
|
# Use sqlite3 as the database for Active Record
|
16
|
-
gem
|
18
|
+
gem 'sqlite3', '~> 1.4'
|
17
19
|
|
18
20
|
# Use the Puma web server [https://github.com/puma/puma]
|
19
|
-
gem
|
21
|
+
gem 'puma', '>= 5.0'
|
20
22
|
|
21
23
|
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
|
22
|
-
gem
|
24
|
+
gem 'importmap-rails'
|
23
25
|
|
24
26
|
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
|
25
|
-
gem
|
27
|
+
gem 'turbo-rails'
|
26
28
|
|
27
29
|
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
|
28
|
-
gem
|
30
|
+
gem 'stimulus-rails'
|
29
31
|
|
30
32
|
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
|
31
|
-
gem
|
33
|
+
gem 'jbuilder'
|
32
34
|
|
33
35
|
# Use Redis adapter to run Action Cable in production
|
34
|
-
gem
|
36
|
+
gem 'redis', '>= 4.0.1'
|
35
37
|
|
36
38
|
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
|
37
39
|
# gem "kredis"
|
@@ -40,33 +42,32 @@ gem "redis", ">= 4.0.1"
|
|
40
42
|
# gem "bcrypt", "~> 3.1.7"
|
41
43
|
|
42
44
|
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
43
|
-
gem
|
45
|
+
gem 'tzinfo-data', platforms: %i[windows jruby]
|
44
46
|
|
45
47
|
# Reduces boot times through caching; required in config/boot.rb
|
46
|
-
gem
|
48
|
+
gem 'bootsnap', require: false
|
47
49
|
|
48
50
|
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
|
49
51
|
# gem "image_processing", "~> 1.2"
|
50
52
|
|
51
53
|
group :development, :test do
|
52
54
|
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
|
53
|
-
gem
|
55
|
+
gem 'debug', platforms: %i[mri windows]
|
54
56
|
end
|
55
57
|
|
56
58
|
group :development do
|
57
59
|
# Use console on exceptions pages [https://github.com/rails/web-console]
|
58
|
-
gem
|
60
|
+
gem 'web-console'
|
59
61
|
|
60
62
|
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
|
61
63
|
# gem "rack-mini-profiler"
|
62
64
|
|
63
65
|
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
|
64
66
|
# gem "spring"
|
65
|
-
|
66
67
|
end
|
67
68
|
|
68
69
|
group :test do
|
69
70
|
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
|
70
|
-
gem
|
71
|
-
gem
|
71
|
+
gem 'capybara'
|
72
|
+
gem 'selenium-webdriver'
|
72
73
|
end
|
data/example/Gemfile.lock
CHANGED
@@ -82,7 +82,7 @@ GEM
|
|
82
82
|
bootsnap (1.17.0)
|
83
83
|
msgpack (~> 1.2)
|
84
84
|
builder (3.2.4)
|
85
|
-
canvas-embed (0.1.
|
85
|
+
canvas-embed (0.1.5)
|
86
86
|
rbnacl (~> 7.1.1)
|
87
87
|
capybara (3.39.2)
|
88
88
|
addressable
|
@@ -251,7 +251,7 @@ PLATFORMS
|
|
251
251
|
|
252
252
|
DEPENDENCIES
|
253
253
|
bootsnap
|
254
|
-
canvas-embed (~> 0.1.
|
254
|
+
canvas-embed (~> 0.1.4)
|
255
255
|
capybara
|
256
256
|
debug
|
257
257
|
importmap-rails
|
data/example/README.md
CHANGED
@@ -10,8 +10,21 @@ After running `bundle install` you can start the Rails server with
|
|
10
10
|
CANVAS_SIGNING_KEY=[your signing key] bin/rails server
|
11
11
|
```
|
12
12
|
|
13
|
-
|
13
|
+
This serves a GET endpoint `generate_token?scopes=[scopes]` where scopes are the scopes you want included in the generated token.
|
14
14
|
|
15
|
-
This can be used in the [React component](https://github.com/canvas/embeds/tree/main/react) to view embedded Canvas charts as they will appear to your users.
|
16
15
|
|
17
|
-
|
16
|
+
This endpoint is used in the [React component](https://github.com/canvas/embeds/tree/main/react) to view embedded Canvas charts as they will appear to your users.
|
17
|
+
|
18
|
+
In order for this to work, you'll need to update the scopes in `ApplicationController` to include the ones relevant to your charts and user.
|
19
|
+
|
20
|
+
# Running
|
21
|
+
|
22
|
+
```
|
23
|
+
bin/rails server
|
24
|
+
```
|
25
|
+
|
26
|
+
This application expects the key in the CANVAS_SIGNING_KEY variable. You can set this by running:
|
27
|
+
|
28
|
+
```
|
29
|
+
CANVAS_SIGNING_KEY=emk_HgwRqhyt.f0533f95ed220910218667124cac2116fsse11daf2aa1ff9938f7fde7a16c203 bin/rails server
|
30
|
+
```
|
data/example/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
4
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
5
|
|
4
|
-
require_relative
|
6
|
+
require_relative 'config/application'
|
5
7
|
|
6
8
|
Rails.application.load_tasks
|
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
include Canvas::Embed
|
2
4
|
|
3
5
|
class ApplicationController < ActionController::Base
|
4
6
|
def generate_token
|
@@ -8,10 +10,10 @@ class ApplicationController < ActionController::Base
|
|
8
10
|
# appropriate for the user
|
9
11
|
begin
|
10
12
|
scopes = ActiveSupport::JSON.decode params[:scopes]
|
11
|
-
rescue StandardError
|
12
|
-
return render :
|
13
|
+
rescue StandardError
|
14
|
+
return render json: { 'message' => 'Scopes were not valid JSON' }, status: 500
|
13
15
|
end
|
14
|
-
token = Canvas::Embed
|
15
|
-
render :
|
16
|
+
token = Canvas::Embed.generate_token(key_hex, scopes, 7200, "usr_test123")
|
17
|
+
render json: { 'token' => token }
|
16
18
|
end
|
17
19
|
end
|
data/example/bin/bundle
CHANGED
@@ -8,46 +8,46 @@
|
|
8
8
|
# this file is here to facilitate running it.
|
9
9
|
#
|
10
10
|
|
11
|
-
require
|
11
|
+
require 'rubygems'
|
12
12
|
|
13
13
|
m = Module.new do
|
14
14
|
module_function
|
15
15
|
|
16
16
|
def invoked_as_script?
|
17
|
-
File.expand_path($
|
17
|
+
File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
|
18
18
|
end
|
19
19
|
|
20
20
|
def env_var_version
|
21
|
-
ENV[
|
21
|
+
ENV['BUNDLER_VERSION']
|
22
22
|
end
|
23
23
|
|
24
24
|
def cli_arg_version
|
25
25
|
return unless invoked_as_script? # don't want to hijack other binstubs
|
26
|
-
return unless
|
26
|
+
return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`
|
27
|
+
|
27
28
|
bundler_version = nil
|
28
29
|
update_index = nil
|
29
30
|
ARGV.each_with_index do |a, i|
|
30
|
-
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
31
|
-
bundler_version = a
|
32
|
-
end
|
31
|
+
bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
33
32
|
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
34
|
-
|
33
|
+
|
34
|
+
bundler_version = Regexp.last_match(1)
|
35
35
|
update_index = i
|
36
36
|
end
|
37
37
|
bundler_version
|
38
38
|
end
|
39
39
|
|
40
40
|
def gemfile
|
41
|
-
gemfile = ENV[
|
41
|
+
gemfile = ENV['BUNDLE_GEMFILE']
|
42
42
|
return gemfile if gemfile && !gemfile.empty?
|
43
43
|
|
44
|
-
File.expand_path(
|
44
|
+
File.expand_path('../Gemfile', __dir__)
|
45
45
|
end
|
46
46
|
|
47
47
|
def lockfile
|
48
48
|
lockfile =
|
49
49
|
case File.basename(gemfile)
|
50
|
-
when
|
50
|
+
when 'gems.rb' then gemfile.sub(/\.rb$/, '.locked')
|
51
51
|
else "#{gemfile}.lock"
|
52
52
|
end
|
53
53
|
File.expand_path(lockfile)
|
@@ -55,8 +55,10 @@ m = Module.new do
|
|
55
55
|
|
56
56
|
def lockfile_version
|
57
57
|
return unless File.file?(lockfile)
|
58
|
+
|
58
59
|
lockfile_contents = File.read(lockfile)
|
59
60
|
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
61
|
+
|
60
62
|
Regexp.last_match(1)
|
61
63
|
end
|
62
64
|
|
@@ -76,20 +78,24 @@ m = Module.new do
|
|
76
78
|
end
|
77
79
|
|
78
80
|
def load_bundler!
|
79
|
-
ENV[
|
81
|
+
ENV['BUNDLE_GEMFILE'] ||= gemfile
|
80
82
|
|
81
83
|
activate_bundler
|
82
84
|
end
|
83
85
|
|
84
86
|
def activate_bundler
|
85
87
|
gem_error = activation_error_handling do
|
86
|
-
gem
|
88
|
+
gem 'bundler', bundler_requirement
|
87
89
|
end
|
88
90
|
return if gem_error.nil?
|
91
|
+
|
89
92
|
require_error = activation_error_handling do
|
90
|
-
require
|
93
|
+
require 'bundler/version'
|
94
|
+
end
|
95
|
+
if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
96
|
+
return
|
91
97
|
end
|
92
|
-
|
98
|
+
|
93
99
|
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
|
94
100
|
exit 42
|
95
101
|
end
|
@@ -104,6 +110,4 @@ end
|
|
104
110
|
|
105
111
|
m.load_bundler!
|
106
112
|
|
107
|
-
if m.invoked_as_script?
|
108
|
-
load Gem.bin_path("bundler", "bundle")
|
109
|
-
end
|
113
|
+
load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script?
|
data/example/bin/importmap
CHANGED
data/example/bin/rails
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../config/application', __dir__)
|
5
|
+
require_relative '../config/boot'
|
6
|
+
require 'rails/commands'
|
data/example/bin/rake
CHANGED
data/example/bin/setup
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'fileutils'
|
3
5
|
|
4
6
|
# path to your application root.
|
5
|
-
APP_ROOT = File.expand_path(
|
7
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
6
8
|
|
7
9
|
def system!(*args)
|
8
10
|
system(*args, exception: true)
|
@@ -13,9 +15,9 @@ FileUtils.chdir APP_ROOT do
|
|
13
15
|
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
|
14
16
|
# Add necessary setup steps to this file.
|
15
17
|
|
16
|
-
puts
|
17
|
-
system!
|
18
|
-
system(
|
18
|
+
puts '== Installing dependencies =='
|
19
|
+
system! 'gem install bundler --conservative'
|
20
|
+
system('bundle check') || system!('bundle install')
|
19
21
|
|
20
22
|
# puts "\n== Copying sample files =="
|
21
23
|
# unless File.exist?("config/database.yml")
|
@@ -23,11 +25,11 @@ FileUtils.chdir APP_ROOT do
|
|
23
25
|
# end
|
24
26
|
|
25
27
|
puts "\n== Preparing database =="
|
26
|
-
system!
|
28
|
+
system! 'bin/rails db:prepare'
|
27
29
|
|
28
30
|
puts "\n== Removing old logs and tempfiles =="
|
29
|
-
system!
|
31
|
+
system! 'bin/rails log:clear tmp:clear'
|
30
32
|
|
31
33
|
puts "\n== Restarting application server =="
|
32
|
-
system!
|
34
|
+
system! 'bin/rails restart'
|
33
35
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'boot'
|
4
|
+
|
5
|
+
require 'rails/all'
|
4
6
|
|
5
7
|
# Require the gems listed in Gemfile, including any gems
|
6
8
|
# you've limited to :test, :development, or :production.
|
@@ -14,7 +16,7 @@ module Blog
|
|
14
16
|
# Please, add to the `ignore` list any other `lib` subdirectories that do
|
15
17
|
# not contain `.rb` files, or that should not be reloaded or eager loaded.
|
16
18
|
# Common ones are `templates`, `generators`, or `middleware`, for example.
|
17
|
-
config.autoload_lib(ignore: %w
|
19
|
+
config.autoload_lib(ignore: %w[assets tasks])
|
18
20
|
|
19
21
|
# Configuration for the application, engines, and railties goes here.
|
20
22
|
#
|
data/example/config/boot.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
4
|
+
|
5
|
+
require 'bundler/setup' # Set up gems listed in the Gemfile.
|
6
|
+
require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/integer/time'
|
2
4
|
|
3
5
|
Rails.application.configure do
|
4
6
|
# Settings specified here will take precedence over those in config/application.rb.
|
@@ -19,13 +21,13 @@ Rails.application.configure do
|
|
19
21
|
|
20
22
|
# Enable/disable caching. By default caching is disabled.
|
21
23
|
# Run rails dev:cache to toggle caching.
|
22
|
-
if Rails.root.join(
|
24
|
+
if Rails.root.join('tmp/caching-dev.txt').exist?
|
23
25
|
config.action_controller.perform_caching = true
|
24
26
|
config.action_controller.enable_fragment_cache_logging = true
|
25
27
|
|
26
28
|
config.cache_store = :memory_store
|
27
29
|
config.public_file_server.headers = {
|
28
|
-
|
30
|
+
'Cache-Control' => "public, max-age=#{2.days.to_i}"
|
29
31
|
}
|
30
32
|
else
|
31
33
|
config.action_controller.perform_caching = false
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Rails.application.config.middleware.insert_before 0, Rack::Cors do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
allow do
|
5
|
+
origins '*'
|
6
|
+
|
7
|
+
resource '*',
|
8
|
+
headers: :any,
|
9
|
+
methods: %i[get post put patch delete options head]
|
10
|
+
end
|
11
|
+
end
|
data/example/config/puma.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This configuration file will be evaluated by Puma. The top-level methods that
|
2
4
|
# are invoked here are part of Puma's configuration DSL. For more information
|
3
5
|
# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
|
@@ -7,29 +9,29 @@
|
|
7
9
|
# Any libraries that use thread pools should be configured to match
|
8
10
|
# the maximum value specified for Puma. Default is set to 5 threads for minimum
|
9
11
|
# and maximum; this matches the default thread size of Active Record.
|
10
|
-
max_threads_count = ENV.fetch(
|
11
|
-
min_threads_count = ENV.fetch(
|
12
|
+
max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
|
13
|
+
min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
|
12
14
|
threads min_threads_count, max_threads_count
|
13
15
|
|
14
16
|
# Specifies that the worker count should equal the number of processors in production.
|
15
|
-
if ENV[
|
16
|
-
require
|
17
|
-
worker_count = Integer(ENV.fetch(
|
17
|
+
if ENV['RAILS_ENV'] == 'production'
|
18
|
+
require 'concurrent-ruby'
|
19
|
+
worker_count = Integer(ENV.fetch('WEB_CONCURRENCY') { Concurrent.physical_processor_count })
|
18
20
|
workers worker_count if worker_count > 1
|
19
21
|
end
|
20
22
|
|
21
23
|
# Specifies the `worker_timeout` threshold that Puma will use to wait before
|
22
24
|
# terminating a worker in development environments.
|
23
|
-
worker_timeout 3600 if ENV.fetch(
|
25
|
+
worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development'
|
24
26
|
|
25
27
|
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
|
26
|
-
port ENV.fetch(
|
28
|
+
port ENV.fetch('PORT', 3001)
|
27
29
|
|
28
30
|
# Specifies the `environment` that Puma will run in.
|
29
|
-
environment ENV.fetch(
|
31
|
+
environment ENV.fetch('RAILS_ENV', 'development')
|
30
32
|
|
31
33
|
# Specifies the `pidfile` that Puma will use.
|
32
|
-
pidfile ENV.fetch(
|
34
|
+
pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid')
|
33
35
|
|
34
36
|
# Allow puma to be restarted by `bin/rails restart` command.
|
35
37
|
plugin :tmp_restart
|