console_runner 0.1.7 → 0.1.8

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0fdcaea27d9c7a47a33276fe97eaadb5063a1bb
4
- data.tar.gz: f67cf5ec2116676fce4b14a7a8b4807f0a42fb17
3
+ metadata.gz: 46251b514ee3ff2c6fe6d1805b58bb7bc8740ebb
4
+ data.tar.gz: 7781c2c0188af33e49ab7bec3e99be229bb756ac
5
5
  SHA512:
6
- metadata.gz: 50ff21a11dbb5b47c459807520468000c69c2279d426444a9a2d37376cf1d5695edbb5fd04253c9de4c3c059c28786491da6cbc4666f15778f5f4e09574731a3
7
- data.tar.gz: 6dc150a981b78e4ff5d572efc948e92f179223f85196ea32a9cc4b370c7521bfc9c68e3db8ff646dea3e70f14dfcc0c5524f7546947a0486127ef690ccb6f64a
6
+ metadata.gz: 1ca1cf2617736897556652cfa6de3c7a894349359d3ab2472f759c7a8def9a0b617e77138e48dbab8e9c77c805451b52ff4aef38fca6ffb8187b9ddc2d62c4cc
7
+ data.tar.gz: 64c9e1747574c79f5ee1b863a7e26ba4a2dd9f98ecd10d8f4cfbab133b02350c34354ef73b5bf451487ea69c7b0dbb875cd597a857d7dae68bb5b68a7705e1f8
data/README.md CHANGED
@@ -100,8 +100,7 @@ Finish Time: 2017-04-11 21:39:40 +0300 (Duration: 0.0 minutes)
100
100
  ```
101
101
 
102
102
  ## ToDo
103
- - fix help menu for action: action help text should be displayed.
104
- - add tests for same methods naming
103
+ - fix help menu for action: action help text should be displayed, list of available actions should be displayed
105
104
  - write good readme
106
105
 
107
106
  ## Development
@@ -114,12 +113,10 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
114
113
 
115
114
  Bug reports and pull requests are welcome on GitHub at https://github.com/yuri-karpovich/console_runner.
116
115
 
117
-
118
116
  ## License
119
117
 
120
118
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
121
119
 
122
-
123
120
  [Gem Version]: https://rubygems.org/gems/console_runner
124
121
  [Build Status]: https://travis-ci.org/yuri-karpovich/console_runner
125
122
  [travis pull requests]: https://travis-ci.org/yuri-karpovich/console_runner/pull_requests
data/lib/cmd_parser.rb CHANGED
@@ -26,9 +26,14 @@ class CmdParser
26
26
 
27
27
  if init_method
28
28
  @init_method = MethodParser.new init_method
29
- same_methods = @init_method.param_tags_names & @init_method.option_tags_names
30
- raise "You have the same name for @param and @option attribute(s): #{same_methods.join(', ')}.
31
- Use different names to `console_runner` be able to run #{@init_method.name} method." if same_methods.count > 0
29
+ same_params = @init_method.param_tags_names & @init_method.option_tags_names
30
+ if same_params.count > 0
31
+ raise(
32
+ ConsoleRunnerError,
33
+ "You have the same name for @param and @option attribute(s): #{same_params.join(', ')}.
34
+ Use different names to `console_runner` be able to run #{@init_method.name} method."
35
+ )
36
+ end
32
37
 
33
38
 
34
39
  @init_method.param_tags.each do |tag|
@@ -57,7 +62,7 @@ Use different names to `console_runner` be able to run #{@init_method.name} meth
57
62
  begin
58
63
  @parser.parse ARGV
59
64
  rescue Trollop::CommandlineError => e
60
- raise "You must provide one of available actions: #{sub_commands.join ', '}" unless sub_commands.include?(ARGV[0])
65
+ raise ConsoleRunnerError, "You must provide one of available actions: #{sub_commands.join ', '}" unless sub_commands.include?(ARGV[0])
61
66
  raise e
62
67
  end
63
68
  end
@@ -71,10 +76,15 @@ Use different names to `console_runner` be able to run #{@init_method.name} meth
71
76
  # Parse method and configure #Trollop
72
77
  def parse_method(method)
73
78
  ARGV.shift
74
- @method = MethodParser.new method
75
- same_methods = @method.param_tags_names & @method.option_tags_names
76
- raise "You have the same name for @param and @option attribute(s): #{same_methods.join(', ')}.
77
- Use different names to `console_runner` be able to run #{@method.name} method." if same_methods.count > 0
79
+ @method = MethodParser.new method
80
+ same_params = @method.param_tags_names & @method.option_tags_names
81
+ if same_params.count > 0
82
+ raise(
83
+ ConsoleRunnerError,
84
+ "You have the same name for @param and @option attribute(s): #{same_params.join(', ')}.
85
+ Use different names to `console_runner` be able to run #{@method.name} method."
86
+ )
87
+ end
78
88
  method_params_tags = @method.param_tags
79
89
 
80
90
  method_params_tags.each do |tag|
@@ -113,14 +123,14 @@ Use different names to `console_runner` be able to run #{@method.name} method."
113
123
  method_params_tags.select { |t| t.tag_name == 'param' }.map(&:name).each do |required_param|
114
124
  next if @method.options_group? required_param
115
125
  unless @method.cmd_opts[required_param.to_sym]
116
- raise "You must specify required parameter: #{required_param}"
126
+ raise ConsoleRunnerError, "You must specify required parameter: #{required_param}"
117
127
  end
118
128
  end
119
129
  end
120
130
 
121
131
  def self.parse_type(yard_type)
122
132
  result = TYPES_MAPPINGS[yard_type]
123
- raise "Unsupported YARD type: #{yard_type}" unless result
133
+ raise ConsoleRunnerError, "Unsupported YARD type: #{yard_type}" unless result
124
134
  result
125
135
  end
126
136
 
@@ -24,8 +24,15 @@ Runnable class should be marked with @#{FileParser::RUNNABLE_TAG} tag"
24
24
  run_method = all_methods.find { |m| m.name == :run }
25
25
 
26
26
 
27
- cmd = ARGV[0]
28
- action_method = runnable_methods.find { |m| m.name.to_s == cmd } # get sub-command
27
+ cmd = ARGV[0]
28
+ action_methods = runnable_methods.select { |m| m.name.to_s == cmd }
29
+ if action_methods.count > 1
30
+ raise(
31
+ ConsoleRunnerError,
32
+ "Class and Instance methods have the same name (#{cmd}). Action name should be unique"
33
+ )
34
+ end
35
+ action_method = action_methods.first
29
36
  action_method ||= run_method
30
37
  cmd_parser = CmdParser.new(runnable_methods, initialize_method)
31
38
  raise ConsoleRunnerError, "Cannot run! You haven't specify any method to run." unless action_method
@@ -1,3 +1,3 @@
1
1
  module ConsoleRunner
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
data/lib/file_parser.rb CHANGED
@@ -5,12 +5,12 @@ require 'console_runner_error'
5
5
  class FileParser
6
6
  RUNNABLE_TAG = :runnable
7
7
 
8
+ # array of #YARD::CodeObjects
8
9
  attr_reader :all_objects
9
10
 
10
11
  # Parse file with #YARD::CLI::Stats
11
12
  #
12
13
  # @param [String] file_path path to the file to be parsed
13
- # @return[Array(YARD::CodeObjects)] array of #YARD::CodeObjects classes
14
14
  def initialize(file_path)
15
15
  raise ConsoleRunnerError "Cannot find file #{file_path}" unless File.exist?(file_path)
16
16
  code = YARD::CLI::Stats.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Karpovich