From 1d91177a030ae3bd8ec6175ae772e3012b5e73a1 Mon Sep 17 00:00:00 2001 From: Ivan Buiko Date: Thu, 9 Apr 2015 18:26:41 +0300 Subject: [PATCH] fix from_environment Addition to the https://github.com/rails/execjs/pull/5 I think it's better to use @const_defined?@ --- lib/execjs/runtimes.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/execjs/runtimes.rb b/lib/execjs/runtimes.rb index 5c51360..5079a48 100644 --- a/lib/execjs/runtimes.rb +++ b/lib/execjs/runtimes.rb @@ -55,15 +55,11 @@ module ExecJS def self.from_environment if name = ENV["EXECJS_RUNTIME"] - if runtime = const_get(name) - if runtime.available? - runtime if runtime.available? - else - raise RuntimeUnavailable, "#{runtime.name} runtime is not available on this system" - end - elsif !name.empty? - raise RuntimeUnavailable, "#{name} runtime is not defined" - end + raise RuntimeUnavailable, "#{name} runtime is not defined" unless const_defined?(name) + runtime = const_get(name) + + raise RuntimeUnavailable, "#{runtime.name} runtime is not available on this system" unless runtime.available? + runtime end end