rubycom 0.2.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzIyZGNiNTNlZGYwNTllMDcwOTFhNzE5YjMyMTE2M2YxZWFiNzM5MA==
5
+ data.tar.gz: !binary |-
6
+ YmI0MWUwNWVkMzExYjUyNjVjOGMwNWVjYzE5ZTNhZDFhMTg4Yjk4OA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ Njc2YzE2YTBkNDNkN2FkZGI4MTZhNWIyNzVkNzdjYjE2YTg5ZDcyYmE1MTg0
10
+ Y2RkMTg1YzY2Yzg2N2M4NTMzY2QzN2Y1MDQ1N2JkZGU2NzhjYWQ0ZWYwMmRk
11
+ YjkyYTg2MTVlNzA3ZmRkZGZjMmExZDIwMmVmNTliMmMxM2JlMzA=
12
+ data.tar.gz: !binary |-
13
+ M2EzNTAwODE5OTdjYzNmNjYxYzc0YjRmZjRlMjU4NGVhNTE3YjI4MzZiNGFh
14
+ ZWVkNDBlY2YxYmRjYzMxNGRiZWYwNzhlMzE2NzE0MmQwMjlkNDhmZjU2ZGQw
15
+ Y2M5Mjg2MjM1OWIwYjE0OWI3OTVmMjBiYmU4OGE3MWU2M2JmNjI=
data/Rakefile CHANGED
@@ -29,9 +29,9 @@ task :package => [:clean, :test, :yard] do
29
29
  end
30
30
 
31
31
  task :install => :package do
32
- system("gem install rubycom-#{Rubycom::VERSION}")
32
+ system("gem install #{File.expand_path(File.dirname(__FILE__))}/rubycom-#{Rubycom::VERSION}.gem")
33
33
  end
34
34
 
35
35
  task :release => :package do
36
- system("gem push ./rubycom-#{Rubycom::VERSION}.gem")
36
+ system("gem push #{File.expand_path(File.dirname(__FILE__))}/rubycom-#{Rubycom::VERSION}.gem")
37
37
  end
@@ -50,6 +50,7 @@ module Rubycom
50
50
  begin
51
51
  raise CLIError, 'No job specified' if arguments[0].nil? || arguments[0].empty?
52
52
  job_hash = YAML.load_file(arguments[0])
53
+ job_hash = {} if job_hash.nil?
53
54
  STDOUT.sync = true
54
55
  if arguments.delete('-test') || arguments.delete('--test')
55
56
  puts "[Test Job #{arguments[0]}]"
@@ -96,6 +97,7 @@ module Rubycom
96
97
  # @param [String] command the name of the Method to call
97
98
  # @param [Array] arguments a String Array representing the arguments for the given command
98
99
  def self.run_command(base, command, arguments=[])
100
+ arguments = [] if arguments.nil?
99
101
  raise CLIError, 'No command specified.' if command.nil? || command.length == 0
100
102
  begin
101
103
  raise CLIError, "Invalid Command: #{command}" unless self.get_top_level_commands(base).include? command.to_sym
@@ -182,6 +184,11 @@ module Rubycom
182
184
  }.reduce(:+) or "No Commands found for #{base}."
183
185
  end
184
186
 
187
+ # Creates a separator with the appropriate spacing to line up a command/description pair in a command list
188
+ #
189
+ # @param [Symbol] sym
190
+ # @param [Integer] spacer_length
191
+ # @return [String] a spaced separator String for use in a command/description list
185
192
  def self.get_separator(sym, spacer_length=0)
186
193
  [].unshift(" " * (spacer_length - sym.to_s.length)).join << " - "
187
194
  end
@@ -195,6 +202,7 @@ module Rubycom
195
202
  raise CLIError, "Can not get usage for #{command_name} with base: #{base||"nil"}" if base.nil? || !base.respond_to?(:included_modules)
196
203
  return 'No command specified.' if command_name.nil? || command_name.length == 0
197
204
  if base.included_modules.map { |mod| mod.name.to_sym }.include?(command_name.to_sym)
205
+ begin
198
206
  mod_const = Kernel.const_get(command_name.to_sym)
199
207
  desc = File.read(mod_const.public_method(mod_const.singleton_methods().first).source_location.first).split(//).reduce(""){|str,c|
200
208
  unless str.gsub("\n",'').gsub(/\s+/,'').include?("module#{mod_const}")
@@ -202,13 +210,21 @@ module Rubycom
202
210
  end
203
211
  str
204
212
  }.split("\n").select{|line| line.strip.match(/^#/)}.map{|line| line.strip.gsub(/^#+/,'')}.join("\n")
213
+ rescue
214
+ desc = ""
215
+ end
205
216
  else
206
217
  raise CLIError, "Invalid command for #{base}, #{command_name}" unless base.public_methods.include?(command_name.to_sym)
207
- desc = self.get_doc(base.public_method(command_name.to_sym))[:desc].join("\n") rescue nil
218
+ desc = self.get_doc(base.public_method(command_name.to_sym))[:desc].join("\n") rescue ""
208
219
  end
209
220
  (desc.nil?||desc=='nil'||desc.length==0) ? "#{command_name}\n" : self.get_formatted_summary(command_name, desc, separator)
210
221
  end
211
222
 
223
+ # Arranges the given command_name and command_description with the separator in a standard format
224
+ #
225
+ # @param [String] command_name the command format
226
+ # @param [String] command_description the description for the given command
227
+ # @param [String] separator optional separator to use
212
228
  def self.get_formatted_summary(command_name, command_description, separator = ' - ')
213
229
  width = 95
214
230
  prefix = command_name.to_s.split(//).map { " " }.join + separator.split(//).map { " " }.join
@@ -245,7 +261,7 @@ module Rubycom
245
261
  else
246
262
  raise CLIError, "Invalid command for #{base}, #{command_name}" unless base.public_methods.include?(command_name.to_sym)
247
263
  m = base.public_method(command_name.to_sym)
248
- method_doc = self.get_doc(m)
264
+ method_doc = self.get_doc(m) || {}
249
265
 
250
266
  msg = "Usage: #{m.name} #{self.get_param_usage(m)}\n"
251
267
  msg << "#{"Parameters:"}\n" unless m.parameters.empty?
@@ -256,6 +272,9 @@ module Rubycom
256
272
  end
257
273
  end
258
274
 
275
+ # Discovers the given Method's parameters and uses them to build a formatted usage string
276
+ #
277
+ # @param [Method] method the Method object to generate usage for
259
278
  def self.get_param_usage(method)
260
279
  return "" if method.parameters.nil? || method.parameters.empty?
261
280
  method.parameters.map { |type, param| {type => param}
@@ -297,7 +316,7 @@ module Rubycom
297
316
  }.reduce(&:merge) || {}
298
317
  end
299
318
 
300
- # Retrieves the given method's documentation from it's source code.
319
+ # Retrieves the given method's documentation from it's source code
301
320
  #
302
321
  # @param [Method] method the Method who's documentation should be retrieved
303
322
  # @return [Hash] a Hash representing the given Method's documentation, documentation parsed as follows:
@@ -316,16 +335,21 @@ module Rubycom
316
335
  }.reduce(&:merge)
317
336
  end
318
337
 
338
+ # Looks up the commands which will be available on the given base Module and returns the longest command name
339
+ # Used in arranging the command list format
340
+ #
341
+ # @param [Module] base the base Module to look up
342
+ # @return [String] the longest command name which will show in a list of commands for the given base Module
319
343
  def self.get_longest_command_name(base)
320
344
  return '' if base.nil?
321
345
  self.get_commands(base, false).map { |_, mod_hash|
322
346
  mod_hash[:commands] + mod_hash[:inclusions].flatten }.flatten.max_by(&:size) or ''
323
347
  end
324
348
 
325
- # Retrieves the singleton methods in the given base
349
+ # Retrieves the singleton methods in the given base and included Modules
326
350
  #
327
351
  # @param [Module] base the module which invoked 'include Rubycom'
328
- # @param [Boolean] all if true recursively search for included modules' commands, if false return only top level commands.
352
+ # @param [Boolean] all if true recursively search for included modules' commands, if false return only top level commands
329
353
  # @return [Hash] a Hash of Symbols representing the command methods in the given base and it's included modules (if all=true)
330
354
  def self.get_commands(base, all=true)
331
355
  return {} if base.nil? || !base.respond_to?(:singleton_methods) || !base.respond_to?(:included_modules)
@@ -341,6 +365,10 @@ module Rubycom
341
365
  }
342
366
  end
343
367
 
368
+ # Discovers the commands specified in the given base without considering the commands contained in sub-modules
369
+ #
370
+ # @param [Module] base the base Module to search
371
+ # @return [Array] a list of command name symbols which are defined in the given Module
344
372
  def self.get_top_level_commands(base)
345
373
  return {} if base.nil? || !base.respond_to?(:singleton_methods) || !base.respond_to?(:included_modules)
346
374
  excluded_commands = [:included, :extended]
@@ -349,6 +377,10 @@ module Rubycom
349
377
  base.included_modules.select { |mod| !excluded_modules.include?(mod.name.to_sym) }.map { |mod| mod.name.to_sym }.flatten
350
378
  end
351
379
 
380
+ # Discovers the commands specified in the given base and included Modules
381
+ #
382
+ # @param [Module] base the base Module to search
383
+ # @return [Hash] a set of command name symbols mapped to containing Modules
352
384
  def self.index_commands(base)
353
385
  excluded_commands = [:included, :extended]
354
386
  excluded_modules = [:Rubycom]
@@ -1,3 +1,3 @@
1
1
  module Rubycom
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["d.purcell.jr+rubycom@gmail.com"]
11
11
  spec.description = %q{Allows command-line access for all singleton methods in an including class. Reads Yard style documentation for command line help output. Uses Yaml for parsing options. Allows the user to make a command-line tool by simply including Rubycom at the bottom.}
12
12
  spec.summary = %q{Converts singleton methods to command-line functions upon inclusion.}
13
- spec.homepage = "http://dannypurcell.github.io/Rubycom"
13
+ spec.homepage = "http://dannypurcell.github.io/rubycom"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -114,6 +114,7 @@ class TestRubycom < Test::Unit::TestCase
114
114
 
115
115
  Commands:
116
116
  test_command - A basic test command
117
+ test_command_no_docs
117
118
  test_command_with_arg - A test_command with one arg
118
119
  test_command_arg_named_arg - A test_command with an arg named arg
119
120
  test_command_with_args - A test_command with two args
@@ -150,6 +151,7 @@ class TestRubycom < Test::Unit::TestCase
150
151
  expected = <<-END.gsub(/^ {4}/, '')
151
152
  Commands:
152
153
  test_command - A basic test command
154
+ test_command_no_docs
153
155
  test_command_with_arg - A test_command with one arg
154
156
  test_command_arg_named_arg - A test_command with an arg named arg
155
157
  test_command_with_args - A test_command with two args
@@ -180,7 +182,7 @@ class TestRubycom < Test::Unit::TestCase
180
182
  end
181
183
 
182
184
  def test_get_top_level_commands
183
- test_command_list = [:test_command, :test_command_with_arg, :test_command_arg_named_arg, :test_command_with_args, :test_command_with_options,
185
+ test_command_list = [:test_command, :test_command_no_docs, :test_command_with_arg, :test_command_arg_named_arg, :test_command_with_args, :test_command_with_options,
184
186
  :test_command_all_options, :test_command_options_arr, :test_command_with_return,
185
187
  :test_command_arg_timestamp, :test_command_arg_false, :test_command_arg_arr,
186
188
  :test_command_arg_hash]
@@ -398,6 +400,7 @@ class TestRubycom < Test::Unit::TestCase
398
400
 
399
401
  Commands:
400
402
  test_command - A basic test command
403
+ test_command_no_docs
401
404
  test_command_with_arg - A test_command with one arg
402
405
  test_command_arg_named_arg - A test_command with an arg named arg
403
406
  test_command_with_args - A test_command with two args
@@ -1,9 +1,12 @@
1
1
  require "#{File.expand_path(File.dirname(__FILE__))}/../../lib/rubycom.rb"
2
2
  require "#{File.expand_path(File.dirname(__FILE__))}/util_test_module.rb"
3
+ require "#{File.expand_path(File.dirname(__FILE__))}/util_test_no_singleton.rb"
3
4
 
4
5
  module UtilTestComposite
5
6
  include UtilTestModule
6
7
 
8
+ include UtilTestNoSingleton
9
+
7
10
  # A test_command in a composite console
8
11
  #
9
12
  # @param [String] test_arg a test argument
@@ -12,6 +12,10 @@ module UtilTestModule
12
12
  puts 'command test'
13
13
  end
14
14
 
15
+ def self.test_command_no_docs
16
+ puts 'command test'
17
+ end
18
+
15
19
  # A test_command with one arg
16
20
  #
17
21
  # @param [String] test_arg a test argument
@@ -1,5 +1,4 @@
1
1
  require "#{File.expand_path(File.dirname(__FILE__))}/../../lib/rubycom.rb"
2
- require "#{File.expand_path(File.dirname(__FILE__))}/util_test_composite.rb"
3
2
 
4
3
  module UtilTestNoSingleton
5
4
  def test_method
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.2.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Danny Purcell
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-14 00:00:00.000000000 Z
11
+ date: 2013-06-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: test-unit
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: yard
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: method_source
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -115,30 +104,29 @@ files:
115
104
  - test/rubycom/util_test_module.rb
116
105
  - test/rubycom/util_test_no_singleton.rb
117
106
  - test/rubycom/utility_tester.rb
118
- homepage: http://dannypurcell.github.io/Rubycom
107
+ homepage: http://dannypurcell.github.io/rubycom
119
108
  licenses:
120
109
  - MIT
110
+ metadata: {}
121
111
  post_install_message:
122
112
  rdoc_options: []
123
113
  require_paths:
124
114
  - lib
125
115
  required_ruby_version: !ruby/object:Gem::Requirement
126
- none: false
127
116
  requirements:
128
117
  - - ! '>='
129
118
  - !ruby/object:Gem::Version
130
119
  version: '0'
131
120
  required_rubygems_version: !ruby/object:Gem::Requirement
132
- none: false
133
121
  requirements:
134
122
  - - ! '>='
135
123
  - !ruby/object:Gem::Version
136
124
  version: '0'
137
125
  requirements: []
138
126
  rubyforge_project:
139
- rubygems_version: 1.8.24
127
+ rubygems_version: 2.0.3
140
128
  signing_key:
141
- specification_version: 3
129
+ specification_version: 4
142
130
  summary: Converts singleton methods to command-line functions upon inclusion.
143
131
  test_files:
144
132
  - test/rubycom/test_rubycom.rb