Class: SleepingKingStudios::Tools::CoreTools
- 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
-
#deprecation_caller_depth ⇒ Integer
readonly
The number of backtrace lines to display when outputting a deprecation warning.
-
#deprecation_strategy ⇒ String
readonly
The current deprecation strategy.
Class Method Summary collapse
-
.deprecation_strategies ⇒ Set
The permitted deprecation strategies for the tool.
Instance Method Summary collapse
-
#deprecate(caller: nil, format: nil, message: nil) ⇒ Object
Prints a deprecation warning or raises an exception.
-
#empty_binding ⇒ Binding
Generates an empty Binding object with an Object as the receiver.
-
#initialize(deprecation_caller_depth: nil, deprecation_strategy: nil, toolbelt: nil) ⇒ CoreTools
constructor
A new instance of CoreTools.
-
#require_each(*file_patterns) ⇒ Object
deprecated
Deprecated.
v1.3.0
Methods inherited from Base
Constructor Details
#initialize(deprecation_caller_depth: nil, deprecation_strategy: nil, toolbelt: nil) ⇒ CoreTools
Returns a new instance of CoreTools.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sleeping_king_studios/tools/core_tools.rb', line 30 def initialize( deprecation_caller_depth: nil, deprecation_strategy: nil, toolbelt: nil ) super(toolbelt:) @deprecation_caller_depth = deprecation_caller_depth || ENV.fetch('DEPRECATION_CALLER_DEPTH', '3').to_i @deprecation_strategy = deprecation_strategy&.to_s || ENV.fetch('DEPRECATION_STRATEGY', 'warn') validate_deprecation_strategy(@deprecation_strategy) end |
Instance Attribute Details
#deprecation_caller_depth ⇒ Integer (readonly)
Returns the number of backtrace lines to display when outputting a deprecation warning.
48 49 50 |
# File 'lib/sleeping_king_studios/tools/core_tools.rb', line 48 def deprecation_caller_depth @deprecation_caller_depth end |
#deprecation_strategy ⇒ String (readonly)
Returns the current deprecation strategy.
51 52 53 |
# File 'lib/sleeping_king_studios/tools/core_tools.rb', line 51 def deprecation_strategy @deprecation_strategy end |
Class Method Details
.deprecation_strategies ⇒ Set
Returns the permitted deprecation strategies for the tool.
21 |
# File 'lib/sleeping_king_studios/tools/core_tools.rb', line 21 def deprecation_strategies = DEPRECATION_STRATEGIES |
Instance Method Details
#deprecate(name, message: nil) ⇒ Object #deprecate(*args, format:, message: nil) ⇒ Object
Prints a deprecation warning or raises an exception.
The behavior of this method depends on the configured deprecation strategy, which can be passed to the constructor or configured using the DEPRECATION_STRATEGY environment variable.
-
If the strategy is ‘warn’ (the default), the formatted message is passed to Kernel.warn, which prints the message to $stderr.
-
If the strategy is ‘raise’, raises a DeprecationError with the message.
-
If the strategy is ‘ignore’, this method does nothing.
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sleeping_king_studios/tools/core_tools.rb', line 105 def deprecate(*, caller: nil, format: nil, message: nil) deprecate("#{self.class.name}#deprecate with :format option") if format case deprecation_strategy when 'ignore' # Do nothing. when 'raise' deprecate_with_exception(*, caller:, format:, message:) when 'warn' deprecate_with_warning(*, caller:, format:, message:) end end |
#empty_binding ⇒ Binding
Generates an empty Binding object with an Object as the receiver.
123 124 125 |
# File 'lib/sleeping_king_studios/tools/core_tools.rb', line 123 def empty_binding Object.new.instance_exec { binding } end |
#require_each(*file_patterns) ⇒ Object
v1.3.0
Expands each file pattern and requires each file.
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/sleeping_king_studios/tools/core_tools.rb', line 132 def require_each(*file_patterns) deprecate("#{self.class.name}#require_each") 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 |