Class: SleepingKingStudios::Tools::CoreTools

Inherits:
Base
  • Object
show all
Defined in:
lib/sleeping_king_studios/tools/core_tools.rb

Overview

Tools for working with an application or working environment.

Defined Under Namespace

Classes: DeprecationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

instance

Constructor Details

#initialize(deprecation_strategy: nil) ⇒ CoreTools

Returns a new instance of CoreTools.



17
18
19
20
# File 'lib/sleeping_king_studios/tools/core_tools.rb', line 17

def initialize(deprecation_strategy: nil)
  @deprecation_strategy =
    deprecation_strategy || ENV.fetch('DEPRECATION_STRATEGY', 'warn')
end

Instance Attribute Details

#deprecation_strategyString (readonly)

Returns The current deprecation strategy.

Returns:

  • (String)

    The current deprecation strategy.



23
24
25
# File 'lib/sleeping_king_studios/tools/core_tools.rb', line 23

def deprecation_strategy
  @deprecation_strategy
end

Instance Method Details

#deprecate(name, message: nil) ⇒ Object #deprecate(*args, format: , message: nil) ⇒ Object

Overloads:

  • #deprecate(name, message: nil) ⇒ Object

    Prints a deprecation warning.

    Parameters:

    • name (String)

      The name of the object, method, or feature that has been deprecated.

    • message (String) (defaults to: nil)

      An optional message to print after the formatted string. Defaults to nil.

  • #deprecate(*args, format: , message: nil) ⇒ Object

    Prints a deprecation warning with the specified format.

    Parameters:

    • args (Array)

      The arguments to pass into the format string.

    • format (String) (defaults to: )

      The format string.

    • message (String) (defaults to: nil)

      An optional message to print after the formatted string. Defaults to nil.



40
41
42
43
44
45
46
47
# File 'lib/sleeping_king_studios/tools/core_tools.rb', line 40

def deprecate(*args, format: nil, message: nil)
  send(
    :"deprecate_as_#{deprecation_strategy}",
    *args,
    format:  format,
    message: message
  )
end

#empty_bindingBinding

Generates an empty Binding object with a BasicObject as the receiver.

Returns:

  • (Binding)

    The empty binding object.



52
53
54
55
56
57
58
59
60
# File 'lib/sleeping_king_studios/tools/core_tools.rb', line 52

def empty_binding
  context = Object.new

  def context.binding
    Kernel.instance_method(:binding).bind(self).call
  end

  context.binding
end

#require_each(*file_patterns) ⇒ Object

Expands each file pattern and requires each file.

Parameters:

  • file_patterns (Array)

    The files to require.



65
66
67
68
69
70
71
72
73
74
75
# 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