From 5c76fdb35beac486244872f5cbe53549d1383a5e Mon Sep 17 00:00:00 2001 From: "Ryan S. Northrup" Date: Fri, 4 Sep 2015 22:50:48 -0700 Subject: [PATCH] Wrap const_defined? in begin/rescue --- lib/bales/application.rb | 12 ++++++++---- lib/bales/command/help.rb | 9 +++++++-- lib/bales/version.rb | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/bales/application.rb b/lib/bales/application.rb index 2d6a171..ec9d44c 100644 --- a/lib/bales/application.rb +++ b/lib/bales/application.rb @@ -174,10 +174,14 @@ def self.parse_command_name(argv) .map { |p| p.capitalize } .join name = "#{const}::#{part}" - if const.const_defined? name - const = eval(name) - depth += 1 - else + begin + if const.const_defined? name + const = eval(name) + depth += 1 + else + break + end + rescue NameError break end end diff --git a/lib/bales/command/help.rb b/lib/bales/command/help.rb index 565f32a..e3fb19b 100644 --- a/lib/bales/command/help.rb +++ b/lib/bales/command/help.rb @@ -41,8 +41,13 @@ def self.commands(ns) end ns.constants - .select { |c| ns.const_defined? "#{ns}::#{c}" } - .select { |c| eval("#{ns}::#{c}").class == Class } + .select { |c| + begin + ns.const_defined? "#{ns}::#{c}" + rescue NameError + false + end + }.select { |c| eval("#{ns}::#{c}").class == Class } .select { |c| eval("#{ns}::#{c}") <= Bales::Command } .map { |c| eval "#{ns}::#{c}" } end diff --git a/lib/bales/version.rb b/lib/bales/version.rb index bc87e2c..b498e2f 100644 --- a/lib/bales/version.rb +++ b/lib/bales/version.rb @@ -1,3 +1,3 @@ module Bales - VERSION="0.1.1" + VERSION="0.1.2" end