mina-hooks 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4aa553044d6d1d55d22dba9a45e4124f6d971644
4
+ data.tar.gz: 8f42095ef8b929d99910aa95bf4540ae32933697
5
+ SHA512:
6
+ metadata.gz: 7b47d4d36bc8bb9e433fe9aa1d35a18edc2af331daf8773bdabe15f6a6f236f541837ed46d179cdbc678cb3f81be83c4eb114e06ec64addf1f510a6619e04743
7
+ data.tar.gz: 2bccac6b8502d061cf7aefc7732dbf779834d26d86cffeb85b8b1c96c97565b98096d4ed82816ac0986e46dfb1165570b3b852dfcf17d41fa99c30a4cf766c23
@@ -0,0 +1,3 @@
1
+ -
2
+ ChangeLog.md
3
+ LICENSE.txt
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+ doc/
3
+ pkg/
4
+ vendor/cache/*.gem
@@ -0,0 +1 @@
1
+ --markup markdown --title "mina-hooks Documentation" --protected
@@ -0,0 +1,6 @@
1
+ ### 0.1 / 2013-11-30
2
+
3
+ * Initial release:
4
+ * Added README
5
+ * Added Mina::Hooks module
6
+ * Added tests
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "kramdown"
7
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Don Morrison
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.
@@ -0,0 +1,108 @@
1
+ # mina-hooks
2
+
3
+ * [Homepage](https://github.com/elskwid/mina-hooks#readme)
4
+ * [Issues](https://github.com/elskwid/mina-hooks/issues)
5
+ * [Documentation](http://rubydoc.info/gems/mina-hooks/frames)
6
+ * [Email](mailto:don at elskwid.net)
7
+
8
+ ## Description
9
+
10
+ Mina plugin to provide local task hooks that run before and after the mina
11
+ commands.
12
+
13
+ Mina uses a queueing system to create a deploy script that executes on the
14
+ remote system but that leaves no way to know when the deploy has started or
15
+ ended.
16
+
17
+ `mina-hooks` gets around this limitation by defining a new `mina_cleanup!`
18
+ method that does the following:
19
+
20
+ * invoke each of the `before_mina_tasks`
21
+ * delegate to the pre-existing `mina_cleanup!`
22
+ * invoke each of the `after_mina_tasks`
23
+
24
+ ### Warning
25
+
26
+ This is extremenly dependant on Mina internals so buyer beware. However,
27
+ it's not a lot of code so we should be fine. It will all be just fine.
28
+
29
+ ## Features
30
+
31
+ ### Easily add tasks
32
+
33
+ Helper methods to add tasks to the lists: (see Usage)
34
+
35
+ * `before_mina`
36
+ * `after_mina`
37
+
38
+ ### Access the task lists
39
+
40
+ Lists of tasks to be run before and after the mina commands:
41
+
42
+ * `before_mina_tasks`
43
+ * `after_mina_tasks`
44
+
45
+ ### Output
46
+ Prints confirmation that the hook is running
47
+
48
+ * `<----- Invoke before mina tasks`
49
+ * `<----- Invoke after mina tasks`
50
+
51
+ Prints task list using Mina-style output if set to verbose
52
+
53
+ * `>> tasks: some:task, some:other:task`
54
+
55
+ ### Still Just Rake
56
+
57
+ Task invocation is still handled by Rake and operates under the same
58
+ rules you've come to expect.
59
+
60
+ ## Usage
61
+
62
+ ```ruby
63
+ require "mina/hooks"
64
+ ```
65
+
66
+ ### before_mina
67
+
68
+ ```ruby
69
+ # Inside your deploy tasks ...
70
+
71
+ before_mina :"some:task", :"some:other:task"
72
+ before_mina :"task:added:later"
73
+
74
+ puts before_mina_tasks.inspect
75
+ # => [:"some:task", :"some:other:task", :"task:added:later"]
76
+
77
+ # ...
78
+ ```
79
+
80
+ ### after_mina
81
+
82
+ ```ruby
83
+ # Still inside your deploy tasks ...
84
+
85
+ after_mina :"some:task", :"some:other:task"
86
+ after_mina :"task:added:later", :"some:task"
87
+
88
+ puts after_mina_tasks.inspect
89
+ # => [:"some:task", :"some:other:task", :"task:added:later", :"some:task"]
90
+
91
+ # ...
92
+ ```
93
+
94
+ Because this is Rake, the above task `some:task` will only be invoked once.
95
+
96
+ ## Requirements
97
+
98
+ * [mina](https://github.com/nadarei/mina)
99
+
100
+ ## Install
101
+
102
+ $ gem install mina-hooks
103
+
104
+ ## Copyright
105
+
106
+ Copyright (c) 2013 Don Morrison
107
+
108
+ See {file:LICENSE.txt} for details.
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ require "rubygems"
4
+
5
+ begin
6
+ require "bundler"
7
+ rescue LoadError => e
8
+ warn e.message
9
+ warn "Run `gem install bundler` to install Bundler."
10
+ exit -1
11
+ end
12
+
13
+ begin
14
+ Bundler.setup(:development)
15
+ rescue Bundler::BundlerError => e
16
+ warn e.message
17
+ warn "Run `bundle install` to install missing gems."
18
+ exit e.status_code
19
+ end
20
+
21
+ require "rake"
22
+
23
+ require "rubygems/tasks"
24
+ Gem::Tasks.new
25
+
26
+ require "rake/testtask"
27
+
28
+ Rake::TestTask.new do |test|
29
+ test.libs << "test"
30
+ test.pattern = "test/**/*_test.rb"
31
+ test.verbose = true
32
+ end
33
+
34
+ require "yard"
35
+ YARD::Rake::YardocTask.new
36
+ task :doc => :yard
@@ -0,0 +1,4 @@
1
+ require "mina/hooks/version"
2
+ require "mina/hooks/plugin"
3
+
4
+ extend Mina::Hooks::Plugin
@@ -0,0 +1,58 @@
1
+ # Provides local task hooks that run before and after the mina_cleanup!.
2
+ #
3
+ # Uses `self.` to cope with the liberal `method_missing` usage in Mina.
4
+
5
+ module Mina
6
+ module Hooks
7
+ module Plugin
8
+
9
+ def before_mina_tasks
10
+ @before_mina_tasks ||= []
11
+ end
12
+
13
+ def after_mina_tasks
14
+ @after_mina_tasks ||= []
15
+ end
16
+
17
+ def before_mina(*tasks)
18
+ @before_mina_tasks = self.before_mina_tasks + tasks
19
+ end
20
+
21
+ def after_mina(*tasks)
22
+ @after_mina_tasks = self.after_mina_tasks + tasks
23
+ end
24
+
25
+ def invoke_before_mina_tasks
26
+ print_local_status "Invoke before mina tasks"
27
+ print_task_list self.before_mina_tasks if verbose_mode?
28
+
29
+ self.before_mina_tasks.each { |task_name| invoke task_name }
30
+ end
31
+
32
+ def invoke_after_mina_tasks
33
+ print_local_status "Invoke after mina tasks"
34
+ print_task_list self.after_mina_tasks if verbose_mode?
35
+
36
+ self.after_mina_tasks.each { |task_name| invoke task_name }
37
+ end
38
+
39
+ def mina_cleanup!
40
+ self.invoke_before_mina_tasks
41
+ super if defined?(super)
42
+ self.invoke_after_mina_tasks
43
+ end
44
+
45
+ def print_task_list(tasks)
46
+ task_list = "tasks: #{tasks.join(", ")}"
47
+ puts " #{color(">>", 32)} #{color(task_list, 32)}"
48
+ end
49
+
50
+ # Prints a status message. (`<-----`)
51
+ def print_local_status(msg)
52
+ puts "" if verbose_mode?
53
+ puts "#{color('<-----', 32)} #{msg}"
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,6 @@
1
+ module Mina
2
+ module Hooks
3
+ # mina-hooks version
4
+ VERSION = "0.1"
5
+ end
6
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path("../lib/mina/hooks/version", __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "mina-hooks"
7
+ gem.version = Mina::Hooks::VERSION
8
+ gem.summary = %q{Mina plugin to provide local task hooks that run before and after the mina commands.}
9
+ gem.description = %q{Mina plugin to provide local task hooks that run before and after the mina commands.}
10
+ gem.license = "MIT"
11
+ gem.authors = ["Don Morrison"]
12
+ gem.email = "don@elskwid.net"
13
+ gem.homepage = "https://github.com/elskwid/mina-hooks#readme"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "mina", "~> 0.3"
21
+
22
+ gem.add_development_dependency "bundler", "~> 1.2"
23
+ gem.add_development_dependency "minitest", "~> 5.0"
24
+ gem.add_development_dependency "rake", "~> 10.0"
25
+ gem.add_development_dependency "rubygems-tasks", "~> 0.2"
26
+ gem.add_development_dependency "yard", "~> 0.8"
27
+ end
@@ -0,0 +1,6 @@
1
+ require "mina/hooks"
2
+
3
+ desc "test hook task"
4
+ task :deploy_test do
5
+ puts "test hooks"
6
+ end
@@ -0,0 +1,71 @@
1
+ require "rubygems"
2
+
3
+ begin
4
+ require "bundler"
5
+ rescue LoadError => e
6
+ STDERR.puts e.message
7
+ STDERR.puts "Run `gem install bundler` to install Bundler."
8
+ exit e.status_code
9
+ end
10
+
11
+ begin
12
+ Bundler.setup(:default, :development, :test)
13
+ rescue Bundler::BundlerError => e
14
+ STDERR.puts e.message
15
+ STDERR.puts "Run `bundle install` to install missing gems."
16
+ exit e.status_code
17
+ end
18
+
19
+ require "mina"
20
+
21
+ # create a regular class scope to test methods
22
+ class MinaClass
23
+ require "mina/hooks"
24
+ extend Mina::Hooks::Plugin
25
+ end
26
+
27
+ # create a test mina app scope
28
+ def mina_app
29
+ Rake.application.instance_eval do
30
+ init "mina"
31
+ require "mina/rake"
32
+ load "test/deploy.rb"
33
+
34
+ # list of tasks that were "invoked"
35
+ @invoked_tasks = []
36
+
37
+ # helper for invoked tasks
38
+ def invoked_tasks
39
+ @invoked_tasks
40
+ end
41
+
42
+ # fake invoke command for testing
43
+ def invoke(task)
44
+ invoked_tasks << task
45
+ end
46
+
47
+ # flag if cleanup method called
48
+ @cleanup_called = false
49
+
50
+ # helper for cleanup method
51
+ def cleanup_called
52
+ @cleanup_called
53
+ end
54
+
55
+ # fake mina_cleanup! command for testing
56
+ def mina_cleanup!
57
+ cleanup_called = true
58
+ end
59
+
60
+ return self
61
+ end
62
+ end
63
+
64
+ # create a task in the scope of the mina app
65
+ def task(name = "test_task", &block)
66
+ mina_app.instance_eval do
67
+ define_task Rake::Task, name, &block
68
+ end
69
+ end
70
+
71
+ require "minitest/autorun"
@@ -0,0 +1,133 @@
1
+ require "helper"
2
+
3
+ describe Mina::Hooks::Plugin do
4
+ describe "class scope" do
5
+ let(:klass) { MinaClass }
6
+
7
+ it "defines before_mina_tasks" do
8
+ assert_respond_to klass, :before_mina_tasks
9
+ end
10
+
11
+ it "defines after_mina_tasks" do
12
+ assert_respond_to klass, :after_mina_tasks
13
+ end
14
+
15
+ it "defines before_mina" do
16
+ assert_respond_to klass, :before_mina
17
+ end
18
+
19
+ it "defines after_mina" do
20
+ assert_respond_to klass, :after_mina
21
+ end
22
+
23
+ it "defines invoke_before_mina_tasks" do
24
+ assert_respond_to klass, :invoke_before_mina_tasks
25
+ end
26
+
27
+ it "defines invoke_after_mina_tasks" do
28
+ assert_respond_to klass, :invoke_after_mina_tasks
29
+ end
30
+
31
+ it "defines mina_cleanup!" do
32
+ assert_respond_to klass, :mina_cleanup!
33
+ end
34
+
35
+ it "defines print_task_list" do
36
+ assert_respond_to klass, :print_task_list
37
+ end
38
+
39
+ it "defines print_local_status" do
40
+ assert_respond_to klass, :print_local_status
41
+ end
42
+
43
+ describe "default task lists" do
44
+ it "before tasks" do
45
+ assert_equal klass.before_mina_tasks, []
46
+ end
47
+
48
+ it "after tasks" do
49
+ assert_equal klass.after_mina_tasks, []
50
+ end
51
+ end # default task lists
52
+ end # class scope
53
+
54
+ describe "rake/mina scope" do
55
+ describe "before mina" do
56
+ let(:task_list) { ["some:task", "some:other:task"] }
57
+
58
+ it "defines before_mina" do
59
+ task do
60
+ assert_respond_to self, :before_mina
61
+ end
62
+ end
63
+
64
+ it "adds tasks to the task list" do
65
+ task do
66
+ before_mina *task_list
67
+ assert_equal before_mina_tasks, task_list
68
+ end
69
+ end
70
+
71
+ it "adds more tasks to the list" do
72
+ task do
73
+ before_mina *task_list
74
+ before_mina "another:task"
75
+ assert_equal before_mina_tasks, (task_list + ["another:task"])
76
+ end
77
+ end
78
+ end # before mina
79
+
80
+ describe "after mina" do
81
+ let(:task_list) { ["after:task"] }
82
+
83
+ it "defines after_mina" do
84
+ task do
85
+ assert_respond_to self, :after_mina
86
+ end
87
+ end
88
+
89
+ it "adds tasks to the task list" do
90
+ task do
91
+ after_mina *task_list
92
+ assert_equal after_mina_tasks, task_list
93
+ end
94
+ end
95
+ end # after mina
96
+
97
+ describe "invoke tasks" do
98
+ let(:task_list) { ["first:task", "second:task", "third:task"]}
99
+
100
+ it "invokes before mina in order" do
101
+ task do
102
+ before_mina *task_list
103
+ invoke_before_mina_tasks
104
+ assert_equal invoked_tasks, task_list
105
+ end
106
+ end
107
+
108
+ it "invokes after mina in order" do
109
+ task do
110
+ after_mina *task_list
111
+ invoke_after_mina_tasks
112
+ assert_equal invoked_tasks, task_list
113
+ end
114
+ end
115
+ end # invoke tasks
116
+
117
+ describe "mina cleanup" do
118
+ let(:before_task_list) { ["before:task:one", "before:task:two"] }
119
+ let(:after_task_list) { ["after:task:one", "after:task:two"] }
120
+
121
+ it "invokes all tasks" do
122
+ task do
123
+ before_mina *before_task_list
124
+ after_mina *after_task_list
125
+ mina_cleanup!
126
+ assert cleanup_called
127
+ assert_equal invoked_tasks, (before_task_list + after_task_list)
128
+ end
129
+ end
130
+ end # mina cleanup
131
+
132
+ end # rake/mina scope
133
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mina-hooks
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Don Morrison
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mina
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubygems-tasks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ description: Mina plugin to provide local task hooks that run before and after the
98
+ mina commands.
99
+ email: don@elskwid.net
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .document
105
+ - .gitignore
106
+ - .yardopts
107
+ - ChangeLog.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - lib/mina/hooks.rb
113
+ - lib/mina/hooks/plugin.rb
114
+ - lib/mina/hooks/version.rb
115
+ - mina-hooks.gemspec
116
+ - test/deploy.rb
117
+ - test/helper.rb
118
+ - test/hooks/plugin_test.rb
119
+ homepage: https://github.com/elskwid/mina-hooks#readme
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.0.3
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Mina plugin to provide local task hooks that run before and after the mina
143
+ commands.
144
+ test_files:
145
+ - test/deploy.rb
146
+ - test/helper.rb
147
+ - test/hooks/plugin_test.rb