thor-plus 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/thor.rb +33 -0
- data/lib/thor/base.rb +9 -0
- data/lib/thor/command.rb +3 -0
- data/lib/thor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f483251a5a8dc7d64817f01855dd09a1f3073de4
|
4
|
+
data.tar.gz: 49de3b45cc64696aa9e98810508224fafddc2a5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7fb604ecf73e9d478625b053a8353cc2f2e763d6dd1b6b749e2b84df262713531e7b22dc0d45764c788bea252ef2762afc892ff0fb3f645c31a10b5ffc2f159
|
7
|
+
data.tar.gz: bae1a232716f10d9243bdefa1e35f42bbc8d59d99bfee0883853a2d3955385b3905698c64f621ca7047282ca9e23b502380a022f1500929843e5c6509229d926
|
data/lib/thor.rb
CHANGED
@@ -27,6 +27,39 @@ class Thor # rubocop:disable ClassLength
|
|
27
27
|
end
|
28
28
|
alias_method :default_task, :default_command
|
29
29
|
|
30
|
+
# Adds a callback method that should be executed before a command is executed.
|
31
|
+
#
|
32
|
+
# ==== Parameters
|
33
|
+
# methods<*String|Symbol>:: Callbacks to execute before command runs.
|
34
|
+
def before_command(*methods)
|
35
|
+
methods.each { |m| register_callback(:before, m) }
|
36
|
+
end
|
37
|
+
alias_method :before_task, :before_command
|
38
|
+
|
39
|
+
# Adds a callback method that should be executed after a task is executed.
|
40
|
+
#
|
41
|
+
# ==== Parameters
|
42
|
+
# methods<*String|Symbol>:: Callbacks to execute after command runs.
|
43
|
+
def after_command(*methods)
|
44
|
+
methods.each { |m| register_callback(:after, m) }
|
45
|
+
end
|
46
|
+
alias_method :after_task, :after_command
|
47
|
+
|
48
|
+
# All callbacks defined for this class & superclass.
|
49
|
+
def callbacks
|
50
|
+
@callbacks ||= from_superclass(:callbacks, {})
|
51
|
+
end
|
52
|
+
|
53
|
+
# Register a callback of generic type.
|
54
|
+
#
|
55
|
+
# ==== Parameters
|
56
|
+
# type<Symbol>:: Type of callback to register.
|
57
|
+
# name<Symbol>:: Name of callback command to run.
|
58
|
+
def register_callback(type, name)
|
59
|
+
callbacks[type.to_sym] ||= []
|
60
|
+
callbacks[type.to_sym] << name.to_sym
|
61
|
+
end
|
62
|
+
|
30
63
|
# Registers another Thor subclass as a command.
|
31
64
|
#
|
32
65
|
# ==== Parameters
|
data/lib/thor/base.rb
CHANGED
@@ -84,6 +84,15 @@ class Thor
|
|
84
84
|
@args = thor_args.remaining
|
85
85
|
end
|
86
86
|
|
87
|
+
# Run callbacks by type.
|
88
|
+
#
|
89
|
+
# ==== Parameters
|
90
|
+
# type<Symbol>:: Type of callbacks to run.
|
91
|
+
def run_callbacks(type)
|
92
|
+
callbacks = self.class.callbacks[type.to_sym] || []
|
93
|
+
callbacks.each { |c| __send__(c) }
|
94
|
+
end
|
95
|
+
|
87
96
|
class << self
|
88
97
|
def included(base) #:nodoc:
|
89
98
|
base.extend ClassMethods
|
data/lib/thor/command.rb
CHANGED
@@ -24,7 +24,10 @@ class Thor
|
|
24
24
|
instance.class.handle_no_command_error(name)
|
25
25
|
elsif public_method?(instance)
|
26
26
|
arity = instance.method(name).arity
|
27
|
+
|
28
|
+
instance.run_callbacks(:before)
|
27
29
|
instance.__send__(name, *args)
|
30
|
+
instance.run_callbacks(:after)
|
28
31
|
elsif local_method?(instance, :method_missing)
|
29
32
|
instance.__send__(:method_missing, name.to_sym, *args)
|
30
33
|
else
|
data/lib/thor/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thor-plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yehuda Katz
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-06-
|
13
|
+
date: 2016-06-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|