motion 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/motion/templates/motion.rb +8 -5
- data/lib/motion.rb +1 -0
- data/lib/motion/action_cable_extentions/declarative_notifications.rb +6 -1
- data/lib/motion/configuration.rb +10 -9
- data/lib/motion/errors.rb +10 -0
- data/lib/motion/revision_calculator.rb +48 -0
- data/lib/motion/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1b1922ab9d0ef3ead51f333bf255e48f1f470a475ccc2463726e7d805d26344
|
4
|
+
data.tar.gz: 57204e95779dfffb7413bb5080da1fb97f8d0bd519a6ae5f07cce80e4bad58f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3240417ce4c5928aa52c17fb1eb89aa641983d1c119d0ad38b7ec05e60c29172ac95fac9b1ab5cba6ef35ea94b7df819b2b917213cfb193dbb749484b485a33a
|
7
|
+
data.tar.gz: b7c973c8a93f0c9fac94fffa21a6b597635e064c4363b55d6718704bfdc5936125956e9116ebafb2936d5c555c95c34dff7e474a873605d49b36b7e0bebefeac
|
@@ -5,13 +5,16 @@ Motion.configure do |config|
|
|
5
5
|
# version of your application. By default, the commit hash from git is used,
|
6
6
|
# but depending on your deployment, this may not be available in production.
|
7
7
|
#
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# Motion automatically calculates your revision by hashing the contents of
|
9
|
+
# files in `revision_paths` The defaults revision paths are:
|
10
|
+
# rails paths, bin, and Gemfile.lock.
|
10
11
|
#
|
11
|
-
#
|
12
|
+
# To change or add to your revision paths, uncomment this line:
|
12
13
|
#
|
13
|
-
#
|
14
|
-
#
|
14
|
+
# config.revision_paths += w(additional_path another_path)
|
15
|
+
#
|
16
|
+
# If you prefer to use git or an environmental variable for the revision
|
17
|
+
# in production, define the revision directly below.
|
15
18
|
#
|
16
19
|
# config.revision =
|
17
20
|
# ENV.fetch("MY_DEPLOYMENT_NUMBER") { `git rev-parse HEAD`.chomp }
|
data/lib/motion.rb
CHANGED
@@ -14,6 +14,7 @@ module Motion
|
|
14
14
|
autoload :LogHelper, "motion/log_helper"
|
15
15
|
autoload :MarkupTransformer, "motion/markup_transformer"
|
16
16
|
autoload :Railtie, "motion/railtie"
|
17
|
+
autoload :RevisionCalculator, "motion/revision_calculator"
|
17
18
|
autoload :Serializer, "motion/serializer"
|
18
19
|
autoload :TestHelpers, "motion/test_helpers"
|
19
20
|
|
@@ -62,7 +62,7 @@ module Motion
|
|
62
62
|
#
|
63
63
|
# See `ActionCable::Channel::PeriodicTimers` for details.
|
64
64
|
def _setup_declarative_notifcation_timer(notification, interval)
|
65
|
-
return if
|
65
|
+
return if _stubbed_connection? ||
|
66
66
|
@_declarative_notifications_timers.include?(notification)
|
67
67
|
|
68
68
|
callback = proc do
|
@@ -77,6 +77,11 @@ module Motion
|
|
77
77
|
active_periodic_timers << timer
|
78
78
|
end
|
79
79
|
|
80
|
+
def _stubbed_connection?
|
81
|
+
defined?(ActionCable::Channel::ConnectionStub) &&
|
82
|
+
connection.is_a?(ActionCable::Channel::ConnectionStub)
|
83
|
+
end
|
84
|
+
|
80
85
|
def _shutdown_declarative_notifcation_timer(notification, *)
|
81
86
|
timer = @_declarative_notifications_timers.delete(notification)
|
82
87
|
return unless timer
|
data/lib/motion/configuration.rb
CHANGED
@@ -59,16 +59,17 @@ module Motion
|
|
59
59
|
Rails.application.key_generator.generate_key("motion:secret")
|
60
60
|
end
|
61
61
|
|
62
|
+
option :revision_paths do
|
63
|
+
require "rails"
|
64
|
+
|
65
|
+
Rails.application.config.paths.dup.tap do |paths|
|
66
|
+
paths.add "bin", glob: "*"
|
67
|
+
paths.add "Gemfile.lock"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
62
71
|
option :revision do
|
63
|
-
|
64
|
-
Motion is automatically inferring the application's revision from git.
|
65
|
-
Depending on your deployment, this may not work for you in production.
|
66
|
-
If it does, add "config.revision = `git rev-parse HEAD`.chomp" to your
|
67
|
-
Motion initializer. If it does not, do something else (probably read an
|
68
|
-
env var or something).
|
69
|
-
MSG
|
70
|
-
|
71
|
-
`git rev-parse HEAD`.chomp
|
72
|
+
RevisionCalculator.new(revision_paths: revision_paths).perform
|
72
73
|
end
|
73
74
|
|
74
75
|
option :renderer_for_connection_proc do
|
data/lib/motion/errors.rb
CHANGED
@@ -148,4 +148,14 @@ module Motion
|
|
148
148
|
super("The revision cannot contain a NULL byte")
|
149
149
|
end
|
150
150
|
end
|
151
|
+
|
152
|
+
class BadRevisionPathsError < Error
|
153
|
+
def initialize
|
154
|
+
super(<<~MSG)
|
155
|
+
Revision paths must be a Rails::Paths::Root object or an object
|
156
|
+
that responds to `all_paths.flat_map(&:existent)` and returns an
|
157
|
+
Array of strings representing full paths.
|
158
|
+
MSG
|
159
|
+
end
|
160
|
+
end
|
151
161
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "digest"
|
4
|
+
require "motion"
|
5
|
+
|
6
|
+
module Motion
|
7
|
+
class RevisionCalculator
|
8
|
+
attr_reader :revision_paths
|
9
|
+
|
10
|
+
def initialize(revision_paths:)
|
11
|
+
@revision_paths = revision_paths
|
12
|
+
end
|
13
|
+
|
14
|
+
def perform
|
15
|
+
derive_file_hash
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def derive_file_hash
|
21
|
+
digest = Digest::MD5.new
|
22
|
+
|
23
|
+
files.each do |file|
|
24
|
+
digest << file # include filename as well as contents
|
25
|
+
digest << File.read(file)
|
26
|
+
end
|
27
|
+
|
28
|
+
digest.hexdigest
|
29
|
+
end
|
30
|
+
|
31
|
+
def existent_paths
|
32
|
+
@existent_paths ||=
|
33
|
+
begin
|
34
|
+
revision_paths.all_paths.flat_map(&:existent)
|
35
|
+
rescue
|
36
|
+
raise BadRevisionPathsError
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def existent_files(path)
|
41
|
+
Dir["#{path}/**/*", path].reject { |f| File.directory?(f) }.uniq
|
42
|
+
end
|
43
|
+
|
44
|
+
def files
|
45
|
+
@files ||= existent_paths.flat_map { |path| existent_files(path) }.sort
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/motion/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alec Larsen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-07-
|
12
|
+
date: 2020-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- lib/motion/log_helper.rb
|
75
75
|
- lib/motion/markup_transformer.rb
|
76
76
|
- lib/motion/railtie.rb
|
77
|
+
- lib/motion/revision_calculator.rb
|
77
78
|
- lib/motion/serializer.rb
|
78
79
|
- lib/motion/test_helpers.rb
|
79
80
|
- lib/motion/version.rb
|
@@ -85,7 +86,7 @@ metadata:
|
|
85
86
|
source_code_uri: https://github.com/unabridged/motion
|
86
87
|
post_install_message: |
|
87
88
|
Friendly reminder: When updating the motion gem, don't forget to update the
|
88
|
-
NPM package as well (`bin/yarn add '@unabridged/motion@0.2.
|
89
|
+
NPM package as well (`bin/yarn add '@unabridged/motion@0.2.2'`).
|
89
90
|
rdoc_options: []
|
90
91
|
require_paths:
|
91
92
|
- lib
|