Sha256: 1cd6c889664589999b367d669c711bb68d2618a4eb9692431790b53db80ebf8f
Contents?: true
Size: 1018 Bytes
Versions: 5
Compression:
Stored size: 1018 Bytes
Contents
# frozen_string_literal: true module EacRubyUtils module Console class DocoptRunner attr_reader :settings private def setting_value(key, required = true) %i[setting_from_argument setting_from_constant].each do |method| value = send(method, key) return value if value end return nil unless required raise "Setting \"#{key}\" not found. Declare #{setting_constant(key, true)} constant, " \ "pass #{key.to_sym} option to #{self.class.name}.new() method." end def setting_from_argument(key) settings[key] end def setting_from_constant(key) constant_name = setting_constant(key) begin self.class.const_get(constant_name) rescue NameError nil end end def setting_constant(key, fullname = false) name = key.to_s.underscore.upcase name = "#{self.class.name}::#{name}" if fullname name end end end end
Version data entries
5 entries across 5 versions & 1 rubygems