rubycom 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZThmMjdiYjc1YjlkMDUxODYxNGQyMmI2YzYzNGI0YTQwMDQ2MGI3Mg==
4
+ YTY4ZmE3MjRkNWJlYmE4Yzg1NGYyOTE1NGNlODFhZWJmZDg5MDFmMg==
5
5
  data.tar.gz: !binary |-
6
- OTY2ZWQzMzI1NGNhOTEyYzM5YTVhZGUwOTgyMTcxMjAyM2Y3MzliYw==
6
+ YjlmZTllNzllZjQ1MDM0ZGQwYzFlMjI2M2I3YjQxMGUwOWFkZjM2Mg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDhlMWRhMDNiODI2Y2RmMjMxNGVhZDU4NDk4YTc3MjljMmE2OWEyNWQ5YTBj
10
- OWZkM2JiZjE2MThjMTRjMzE0NjM2YzI5YzliMmU3NzZjZmViZWE1ODgyODMw
11
- MTM5YTYyZjYyYjcxNzkyY2ZjYWUzZDA1NWNjNjlmYjk0MzlhYzk=
9
+ NDQxOGU4ZTU3ZmFhZmQ3NjA2Y2QwMjIxN2Y2NTNiZjc1NzRmYjE5ZTZjMTJj
10
+ ZDVlYjVhZGFkNzBlMjMwZWI3YTkyN2QzZDUwNTY1NTNmODIwN2Y1OWQyMjI4
11
+ ZDU5NzRlODk5MDc4MzI1ODk2YzZmZmUzNWI0ZTdkYWM4NjQ4MWI=
12
12
  data.tar.gz: !binary |-
13
- ZWEyZThiOGJiMzU2NDYzYzlhMmFlZTM3Yjc2YjY3YTE3YzI5MTUzMGQyYmJh
14
- Yjc3ZmE2MWE0MGJiNzY0Njg5Mzc5YzUyYmNlNDZhZDRlN2IxMmM4MTNhZGFm
15
- ZDI0MWYzNDE1M2IzMjJhNjQzYmI4NjEwNjUzZjYxYWQ5NjhhZDc=
13
+ ZDg3YTIyODAwYmFlZWFjODM0ZGI3ODNjODU5MTk5OTlkN2ZjNDMzZDFmZGNl
14
+ NTVjMzIwOTVlZTBlZDBkODFjOTIyZTYxOGE0MTBmMTE2NjY4OWQ5NDYwMDg3
15
+ ZmZmY2JkZjdiNjE5YzFkNmIwNjBhM2UzNGYwMzViMmM2ODg2NmU=
@@ -1,3 +1,4 @@
1
+ require "#{File.dirname(__FILE__)}/rubycom/base_inclusion_runner.rb"
1
2
  require "#{File.dirname(__FILE__)}/rubycom/completions.rb"
2
3
  require "#{File.dirname(__FILE__)}/rubycom/arg_parse.rb"
3
4
  require "#{File.dirname(__FILE__)}/rubycom/singleton_commands.rb"
@@ -31,30 +32,11 @@ module Rubycom
31
32
  class ParameterExtractError < RubycomError;
32
33
  end
33
34
 
34
-
35
- # Determines whether the including module was executed by a gem binary
36
- #
37
- # @param [String] base_file_path the path to the including module's source file
38
- # @return [Boolean] true|false
39
- def self.is_executed_by_gem?(base_file_path)
40
- Gem.loaded_specs.map { |k, s|
41
- {k => {name: "#{s.name}-#{s.version}", executables: s.executables}}
42
- }.reduce({}, &:merge).map { |_, s|
43
- base_file_path.include?(s[:name]) && s[:executables].include?(File.basename(base_file_path))
44
- }.flatten.reduce(&:|)
45
- end
46
-
47
35
  # Detects that Rubycom was included in another module and calls Rubycom#run
48
36
  #
49
37
  # @param [Module] base the module which invoked 'include Rubycom'
50
38
  def self.included(base)
51
- base_file_path = caller.first.gsub(/:\d+:.+/, '')
52
- if base.class == Module && (base_file_path == $0 || self.is_executed_by_gem?(base_file_path))
53
- base.module_eval {
54
- Rubycom.run(base, ARGV)
55
- }
56
- end
57
- nil
39
+ Rubycom::BaseInclusionRunner.run(caller, Rubycom.public_method(:run), base, ARGV)
58
40
  end
59
41
 
60
42
  # Main entry point for Rubycom. Uses #run_command to discover and run commands
@@ -0,0 +1,36 @@
1
+ module Rubycom
2
+ module BaseInclusionRunner
3
+
4
+ # Calls the given run_fn with the given base and args if the base was
5
+ # run from the command line in it's home folder or from an installed gem library
6
+ #
7
+ # @param [Array] the result from Kernel.caller as called from an included module within base
8
+ # if the first caller entry matches $0 then the base module was executed from it's home folder
9
+ # @param [Method|Proc] to be run if run criteria are satisfied
10
+ # @param [Module] the base Module to test against and to send to the run_fn
11
+ # @param [Array] args a String Array representing the arguments to be passed to run_fn
12
+ # @return nil
13
+ def self.run(caller, run_fn, base, args)
14
+ base_file_path = caller.first.gsub(/:\d+:.+/, '')
15
+ if base.class == Module && (base_file_path == $0 || self.is_executed_by_gem?(base_file_path))
16
+ base.module_eval {
17
+ run_fn.call(base, args)
18
+ }
19
+ end
20
+ nil
21
+ end
22
+
23
+ # Determines whether the including module was executed by a gem binary
24
+ #
25
+ # @param [String] base_file_path the path to the including module's source file
26
+ # @return [Boolean] true|false
27
+ def self.is_executed_by_gem?(base_file_path)
28
+ Gem.loaded_specs.map { |k, s|
29
+ {k => {name: "#{s.name}-#{s.version}", executables: s.executables}}
30
+ }.reduce({}, &:merge).map { |_, s|
31
+ base_file_path.include?(s[:name]) && s[:executables].include?(File.basename(base_file_path))
32
+ }.flatten.reduce(&:|)
33
+ end
34
+
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module Rubycom
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Purcell
@@ -110,6 +110,7 @@ files:
110
110
  - Rakefile
111
111
  - lib/rubycom.rb
112
112
  - lib/rubycom/arg_parse.rb
113
+ - lib/rubycom/base_inclusion_runner.rb
113
114
  - lib/rubycom/command_interface.rb
114
115
  - lib/rubycom/completions.rb
115
116
  - lib/rubycom/error_handler.rb