conditional_capistrano 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc3085020b2ca58897de31421534673847407529
4
- data.tar.gz: 3378e5a30a4ff7a10b718ccb1c376112723de2e5
3
+ metadata.gz: f45de9060a9828612ef331630eed9a86818c1d24
4
+ data.tar.gz: 628b71a9a4735e2777aa79fe794fb8fd2965fbe6
5
5
  SHA512:
6
- metadata.gz: 5a3d6e3884fff3858ab52779902fcf86645cdf06c518f780d8953c7b8820953a701e54689d369928a767c5b5f0809a886f5a49810825dfd38f64bd808cc3a08d
7
- data.tar.gz: 2fa696d924c08c19f5d77cbe250ea0007be2dbe619413b141074cb2a6ddc2d56fef20d95b9228ab30d3e40a8afa9a9cbf477a3b695b2e9a770c9125fb8463632
6
+ metadata.gz: fc86f11b5fe49a3e95393ddb388b3e9aad5aff58fdecf40b766753ff3cf3187a487ca6f1abe659e38e74e182e2518ebad6bf642ab5b307d78a49de6b37c17da2
7
+ data.tar.gz: 2f67842e3830cfd5c186f61a73456c97c1a5795c17231c9b8eeb94bd36fb4038fde8f4d76db2c6bdafacdbe5d7232622ef18af39ad987ee711467ce1e6e55f58
data/README.md CHANGED
@@ -23,10 +23,15 @@ Simply require the capistrano module in your `config/deploy.rb` file:
23
23
 
24
24
  require 'conditional_capistrano/capistrano'
25
25
 
26
- Then add some options to the task scheduling:
26
+ Then add some options to the tasks:
27
27
 
28
- after "key_vault:symlink", "key_vault:check", when_changed: "config/key_vault.yml"
29
- after "deploy:symlink_configs", "assets:compile", when_changed: %w[app/assets Gemfile Gemfile.lock config/application.rb]
28
+ task :compile, roles: :assets, when_changed: %w[app/assets Gemfile Gemfile.lock config/application.rb] do
29
+ ...
30
+ end
31
+
32
+ task :check, roles: :app, when_changed: "config/key_vault.yml" do
33
+ ...
34
+ end
30
35
 
31
36
  You can either mention single files or whole folders, which will be checked for any
32
37
  changes within.
@@ -0,0 +1,23 @@
1
+ module ConditionalCapistrano
2
+ module Capistrano
3
+ module TaskDefinition
4
+ def self.included(base)
5
+ base.class_eval do
6
+ include InstanceMethods
7
+ end
8
+ end
9
+
10
+ module InstanceMethods
11
+ def check_for_path_changes?
12
+ options.has_key? :when_changed
13
+ end
14
+
15
+ def paths_to_check
16
+ Array options[:when_changed]
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ Capistrano::TaskDefinition.send :include, ConditionalCapistrano::Capistrano::TaskDefinition
@@ -1,49 +1,38 @@
1
+ require 'conditional_capistrano/capistrano/task_definition'
2
+
1
3
  module ConditionalCapistrano
2
4
  module Capistrano
3
5
  def self.included(base)
4
6
  base.class_eval do
5
7
  include InstanceMethods
6
8
 
7
- alias_method :applies_to_without_file_check?, :applies_to?
8
- alias_method :applies_to?, :applies_to_with_file_check?
9
+ alias_method :execute_task_without_paths_check, :execute_task
10
+ alias_method :execute_task, :execute_task_with_paths_check
9
11
  end
10
12
  end
11
13
 
12
14
  module InstanceMethods
13
- def applies_to_with_file_check?(task)
14
- return false if check_for_changes? && !trigger?(*paths_to_check)
15
-
16
- applies_to_without_file_check?(task)
17
- end
15
+ def execute_task_with_paths_check(task)
16
+ return if task.check_for_path_changes? && !trigger?(task)
18
17
 
19
- private
20
-
21
- def check_for_changes?
22
- options.has_key?(:when_changed)
18
+ execute_task_without_paths_check task
23
19
  end
24
20
 
25
- def paths_to_check
26
- Array(options[:when_changed])
27
- end
28
-
29
- def trigger?(*paths)
30
- paths.find { |path| changed_files.find { |p| p[0, path.length] == path } }
21
+ def trigger?(task)
22
+ task.paths_to_check.find { |path| changed_files.find { |p| p[0, path.length] == path } }
31
23
  rescue IndexError
32
24
  false
33
25
  end
34
26
 
35
- def changed_files
36
- @changed_files ||=
37
- config.capture(
38
- "cd #{fetch(:repository_cache)} && git diff --name-only #{fetch(:current_git_tag)} HEAD | cat"
39
- ).strip.split
40
- end
27
+ private
41
28
 
42
- def fetch(key)
43
- config.fetch key
29
+ def changed_files
30
+ capture(
31
+ "cd #{repository_cache} && git diff --name-only #{current_git_tag} HEAD | cat"
32
+ ).strip.split
44
33
  end
45
34
  end
46
35
  end
47
36
  end
48
37
 
49
- Capistrano::Callback.send :include, ConditionalCapistrano::Capistrano
38
+ Capistrano::Configuration.send :include, ConditionalCapistrano::Capistrano
@@ -1,3 +1,3 @@
1
1
  module ConditionalCapistrano
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,23 @@
1
+ module Capistrano; end
2
+ module Capistrano
3
+ class TaskDefinition
4
+ attr_reader :options
5
+ end
6
+ end
7
+
8
+ require 'conditional_capistrano/capistrano/task_definition'
9
+
10
+ describe Capistrano::TaskDefinition do
11
+
12
+ describe "#check_for_path_changes?" do
13
+ it "returns true if no 'when_changed' options are present" do
14
+ subject.stub :options => {}
15
+ subject.check_for_path_changes?.should_not be
16
+ end
17
+
18
+ it "returns false if 'when_changed' options are present" do
19
+ subject.stub :options => { when_changed: "path" }
20
+ subject.check_for_path_changes?.should be
21
+ end
22
+ end
23
+ end
@@ -1,53 +1,80 @@
1
1
  module Capistrano; end
2
- class Capistrano::Callback
3
- attr_reader :options
4
-
5
- def initialize(options)
6
- @options = options
2
+ module Capistrano
3
+ class Configuration
4
+ def execute_task(task)
5
+ "original"
6
+ end
7
7
  end
8
+ end
8
9
 
9
- def applies_to?(task)
10
- "original"
10
+ module Capistrano
11
+ class TaskDefinition
11
12
  end
12
13
  end
13
14
 
14
15
  require 'conditional_capistrano/capistrano'
15
16
 
16
- describe Capistrano::Callback do
17
+ describe Capistrano::Configuration do
18
+
19
+ describe "#applies_to_with_paths_check?" do
20
+ let(:task) { Capistrano::TaskDefinition.new }
21
+
22
+ it "falls back to the original if this task doesn't require a path check" do
23
+ task.stub :check_for_path_changes? => false
24
+ subject.execute_task(task).should == "original"
25
+ end
26
+
27
+ context "when path check is required" do
28
+ before do
29
+ task.stub :check_for_path_changes? => true
30
+ end
31
+
32
+ it "returns false if files have been specified, but haven't changed" do
33
+ subject.stub :trigger? => false
34
+ subject.execute_task(task).should_not be
35
+ end
17
36
 
18
- describe "#applies_to_with_file_check?" do
19
- it "falls back to the original 'applies_to?' if no 'when_changed' options were found" do
20
- Capistrano::Callback.new({}).applies_to?("test").should == "original"
37
+ it "falls back to the original if files have been specified, and have changed" do
38
+ subject.stub :trigger? => true
39
+ subject.execute_task(task).should == "original"
40
+ end
21
41
  end
42
+ end
22
43
 
23
- it "returns false if files have been specified, but haven't changed" do
24
- callback = Capistrano::Callback.new(when_changed: "file")
25
- callback.stub :trigger? => false
44
+ describe "#trigger?" do
45
+ let(:task) { Capistrano::TaskDefinition.new }
26
46
 
27
- callback.applies_to?("test").should_not be
47
+ it "returns false if the task doesn't have any paths to check" do
48
+ task.stub paths_to_check: []
49
+ subject.trigger?(task).should_not be
28
50
  end
29
51
 
30
- it "falls back to the original if files have been specified, and have changed" do
31
- callback = Capistrano::Callback.new(when_changed: "file")
32
- callback.stub :trigger? => true
52
+ it "returns false if no files have changed" do
53
+ task.stub paths_to_check: %w[path/to/file]
54
+ subject.stub changed_files: []
33
55
 
34
- callback.applies_to?("test").should == "original"
56
+ subject.trigger?(task).should_not be
35
57
  end
36
58
 
37
- context "possible file options" do
38
- it "allows a single file" do
39
- callback = Capistrano::Callback.new(when_changed: "file")
59
+ it "returns true if we have matching files" do
60
+ task.stub paths_to_check: %w[path/to/file]
61
+ subject.stub changed_files: %w[path/to/file]
40
62
 
41
- callback.should_receive(:trigger?).with "file"
42
- callback.applies_to? "test"
43
- end
63
+ subject.trigger?(task).should be
64
+ end
44
65
 
45
- it "allows an array of files" do
46
- callback = Capistrano::Callback.new(when_changed: %w[file1 file2])
66
+ it "returns false if we files that don't match" do
67
+ task.stub paths_to_check: %w[path/to/file1]
68
+ subject.stub changed_files: %w[path/to/file2]
47
69
 
48
- callback.should_receive(:trigger?).with "file1", "file2"
49
- callback.applies_to? "test"
50
- end
70
+ subject.trigger?(task).should_not be
71
+ end
72
+
73
+ it "returns true if we have files that match a path" do
74
+ task.stub paths_to_check: %w[path/to]
75
+ subject.stub changed_files: %w[path/to/file]
76
+
77
+ subject.trigger?(task).should be
51
78
  end
52
79
  end
53
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conditional_capistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - redbubble
@@ -68,7 +68,9 @@ files:
68
68
  - conditional_capistrano.gemspec
69
69
  - lib/conditional_capistrano.rb
70
70
  - lib/conditional_capistrano/capistrano.rb
71
+ - lib/conditional_capistrano/capistrano/task_definition.rb
71
72
  - lib/conditional_capistrano/version.rb
73
+ - spec/conditional_capistrano/capistrano/task_definition_spec.rb
72
74
  - spec/conditional_capistrano/capistrano_spec.rb
73
75
  homepage: ''
74
76
  licenses:
@@ -96,4 +98,5 @@ specification_version: 4
96
98
  summary: Execute capistrano task's only when certain path's have changed since the
97
99
  last deploy
98
100
  test_files:
101
+ - spec/conditional_capistrano/capistrano/task_definition_spec.rb
99
102
  - spec/conditional_capistrano/capistrano_spec.rb