Sha256: 3b5ffcf16111d8142b75a0b082efc843b7092e20cd1c0811e904e2d3d8cace4b
Contents?: true
Size: 1.4 KB
Versions: 4
Compression:
Stored size: 1.4 KB
Contents
# frozen_string_literal: true module Lite module Command module Utils module_function def monotonic_time Process.clock_gettime(Process::CLOCK_MONOTONIC) end def pretty_exception(exception) return if exception.nil? "[#{exception.class.name}] #{exception.message}".chomp(".") end def descendant_of?(object, other) object_class = object.respond_to?(:new) ? object : object.class other_class = other.respond_to?(:new) ? other : other.class !!(object_class <= other_class) end def cmd_try(object, method_name, *args, include_private: true) return unless object.respond_to?(method_name, include_private) object.send(method_name, *args) end def cmd_call(object, argument) if argument.is_a?(Symbol) || argument.is_a?(String) object.send(argument) elsif argument.is_a?(Proc) object.instance_eval(&argument) else argument end end def cmd_eval(object, options = {}) if options[:if] && options[:unless] cmd_call(object, options[:if]) && !cmd_call(object, options[:unless]) elsif options[:if] cmd_call(object, options[:if]) elsif options[:unless] !cmd_call(object, options[:unless]) else options.fetch(:default, true) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
lite-command-3.3.3 | lib/lite/command/utils.rb |
lite-command-3.3.2 | lib/lite/command/utils.rb |
lite-command-3.3.1 | lib/lite/command/utils.rb |
lite-command-3.3.0 | lib/lite/command/utils.rb |