class SleepingKingStudios::Tools::CoreTools
Tools
for working with an application or working environment.
Attributes
deprecation_strategy[R]
@return [String] The current deprecation strategy.
Public Class Methods
new(deprecation_strategy: nil)
click to toggle source
@param deprecation_strategy
[String] The name of the strategy used when
deprecated code is called. Must be 'ignore', 'raise', or 'warn'.
Calls superclass method
# File lib/sleeping_king_studios/tools/core_tools.rb, line 21 def initialize(deprecation_strategy: nil) super() @deprecation_strategy = deprecation_strategy || ENV.fetch('DEPRECATION_STRATEGY', 'warn') end
Public Instance Methods
deprecate(*args, format: nil, message: nil)
click to toggle source
@overload deprecate(name, message: nil)
Prints a deprecation warning. @param name [String] The name of the object, method, or feature that has been deprecated. @param message [String] An optional message to print after the formatted string. Defaults to nil.
@overload deprecate(*args, format:, message: nil)
Prints a deprecation warning with the specified format. @param args [Array] The arguments to pass into the format string. @param format [String] The format string. @param message [String] An optional message to print after the formatted string. Defaults to nil.
# File lib/sleeping_king_studios/tools/core_tools.rb, line 46 def deprecate(*args, format: nil, message: nil) send( :"deprecate_as_#{deprecation_strategy}", *args, format: format, message: message ) end
empty_binding()
click to toggle source
Generates an empty Binding object with an Object as the receiver.
@return [Binding] The empty binding object.
# File lib/sleeping_king_studios/tools/core_tools.rb, line 58 def empty_binding Object.new.instance_exec { binding } end
require_each(*file_patterns)
click to toggle source
Expands each file pattern and requires each file.
@param file_patterns [Array] The files to require.
# File lib/sleeping_king_studios/tools/core_tools.rb, line 65 def require_each(*file_patterns) file_patterns.each do |file_pattern| if file_pattern.include?('*') Dir[file_pattern].each do |file_name| Kernel.require file_name end else Kernel.require file_pattern end end end
Private Instance Methods
deprecate_as_ignore(*_args, **_kwargs)
click to toggle source
# File lib/sleeping_king_studios/tools/core_tools.rb, line 79 def deprecate_as_ignore(*_args, **_kwargs); end
deprecate_as_raise(*args, format: nil, message: nil)
click to toggle source
# File lib/sleeping_king_studios/tools/core_tools.rb, line 81 def deprecate_as_raise(*args, format: nil, message: nil) format ||= '%s has been deprecated.' str = format % args str << ' ' << message if message raise DeprecationError, str, caller(2..-1) end
deprecate_as_warn(*args, format: nil, message: nil)
click to toggle source
# File lib/sleeping_king_studios/tools/core_tools.rb, line 90 def deprecate_as_warn(*args, format: nil, message: nil) format ||= '[WARNING] %s has been deprecated.' str = format % args str << ' ' << message if message str << "\n called from #{external_caller}" Kernel.warn str end
external_caller()
click to toggle source
# File lib/sleeping_king_studios/tools/core_tools.rb, line 101 def external_caller caller.find do |line| !( line.include?('forwardable.rb') || line.include?('sleeping_king_studios-tools') ) end end