Sha256: 17c68e3bd3a0e22a1e70fef9d90440c81171e45db2154011da2197ae84475725
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 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 try(object, method_name, *args, include_private: true) return unless object.respond_to?(method_name, include_private) object.send(method_name, *args) end def 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 evaluate(object, options = {}) if options[:if] && options[:unless] call(object, options[:if]) && !call(object, options[:unless]) elsif options[:if] call(object, options[:if]) elsif options[:unless] !call(object, options[:unless]) else options.fetch(:default, true) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lite-command-3.2.1 | lib/lite/command/utils.rb |