thor-plus 0.2.0 → 0.3.1

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: f483251a5a8dc7d64817f01855dd09a1f3073de4
4
- data.tar.gz: 49de3b45cc64696aa9e98810508224fafddc2a5d
3
+ metadata.gz: 3dfe41e5f6475c9cecd7c40a7d1b821c0a3c9aa5
4
+ data.tar.gz: 3ae375b919909902c286778693db87b98b0c9991
5
5
  SHA512:
6
- metadata.gz: c7fb604ecf73e9d478625b053a8353cc2f2e763d6dd1b6b749e2b84df262713531e7b22dc0d45764c788bea252ef2762afc892ff0fb3f645c31a10b5ffc2f159
7
- data.tar.gz: bae1a232716f10d9243bdefa1e35f42bbc8d59d99bfee0883853a2d3955385b3905698c64f621ca7047282ca9e23b502380a022f1500929843e5c6509229d926
6
+ metadata.gz: af4e05abca2333347f3664485b64bb230bc306bc39fe0c896bd66898c9d576f90734d4436bf4ca3c4902ee1a348ede0bd2139052d36338d80929ed05eb22ed6e
7
+ data.tar.gz: 8915fb4d9d2e5e0dd75651bca6e3736a7194550aa2d732a87ce6a793dce97a28cc9680b6240e95be733837aded349e11a495a503789943849b719a5b940ce6fa
data/lib/thor.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  require "set"
2
2
  require "thor/base"
3
3
 
4
+ require 'active_support/callbacks'
5
+
4
6
  class Thor # rubocop:disable ClassLength
7
+ include ActiveSupport::Callbacks
8
+ define_callbacks :invoke
9
+
5
10
  class << self
6
11
  # Allows for custom "Command" package naming.
7
12
  #
@@ -31,8 +36,8 @@ class Thor # rubocop:disable ClassLength
31
36
  #
32
37
  # ==== Parameters
33
38
  # methods<*String|Symbol>:: Callbacks to execute before command runs.
34
- def before_command(*methods)
35
- methods.each { |m| register_callback(:before, m) }
39
+ def before_command(*arguments)
40
+ set_callback :invoke, :before, *arguments
36
41
  end
37
42
  alias_method :before_task, :before_command
38
43
 
@@ -40,26 +45,11 @@ class Thor # rubocop:disable ClassLength
40
45
  #
41
46
  # ==== Parameters
42
47
  # methods<*String|Symbol>:: Callbacks to execute after command runs.
43
- def after_command(*methods)
44
- methods.each { |m| register_callback(:after, m) }
48
+ def after_command(*arguments)
49
+ set_callback :invoke, :after, *arguments
45
50
  end
46
51
  alias_method :after_task, :after_command
47
52
 
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
-
63
53
  # Registers another Thor subclass as a command.
64
54
  #
65
55
  # ==== Parameters
data/lib/thor/base.rb CHANGED
@@ -23,7 +23,7 @@ class Thor
23
23
  TEMPLATE_EXTNAME = ".tt"
24
24
 
25
25
  module Base
26
- attr_accessor :options, :parent_options, :args
26
+ attr_accessor :current_command, :options, :parent_options, :args
27
27
 
28
28
  # It receives arguments in an Array and two hashes, one for options and
29
29
  # other for configuration.
@@ -84,13 +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) }
87
+ # Execute a method with callbacks.
88
+ def execute_command(name, arguments)
89
+ @current_command = name.to_sym
90
+
91
+ run_callbacks :invoke do
92
+ __send__(name, *arguments)
93
+ end
94
+
95
+ @current_command = nil
94
96
  end
95
97
 
96
98
  class << self
data/lib/thor/command.rb CHANGED
@@ -24,10 +24,7 @@ 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)
29
- instance.__send__(name, *args)
30
- instance.run_callbacks(:after)
27
+ instance.execute_command(name, args)
31
28
  elsif local_method?(instance, :method_missing)
32
29
  instance.__send__(:method_missing, name.to_sym, *args)
33
30
  else
data/lib/thor/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Thor
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -18,4 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.required_rubygems_version = ">= 1.3.5"
19
19
  spec.summary = spec.description
20
20
  spec.version = Thor::VERSION
21
+
22
+ # Active Support is a collection of utility classes and standard library extensions that were found useful for the Rails framework.
23
+ # https://github.com/rails/rails/tree/master/activesupport
24
+ spec.add_dependency 'activesupport', '~> 4'
21
25
  end
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.2.0
4
+ version: 0.3.1
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-09 00:00:00.000000000 Z
13
+ date: 2016-06-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -26,6 +26,20 @@ dependencies:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
28
  version: '1.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: activesupport
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '4'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '4'
29
43
  description: ThorPlus is an improvement upon the Thor command line tool suite.
30
44
  email: andrew@andrewpage.me
31
45
  executables:
@@ -71,7 +85,7 @@ files:
71
85
  - lib/thor/shell/html.rb
72
86
  - lib/thor/util.rb
73
87
  - lib/thor/version.rb
74
- - thor.gemspec
88
+ - thor-plus.gemspec
75
89
  homepage: http://whatisthor.com/
76
90
  licenses:
77
91
  - MIT