Class: SleepingKingStudios::Tools::Toolbelt

Inherits:
BasicObject
Defined in:
lib/sleeping_king_studios/tools/toolbelt.rb

Overview

Helper object for quick access to all available tools.

Specific tools can be accessed by name. For example, to access the configured instance of ArrayTools, call Toolbelt#array_tools. Certain tools also define a shorthand - for example, the array_tools instance can also be accessed using Toolbelt#ary.

Examples:

toolbelt = SleepingKingStudios::Tools::Toolbelt.new

toolbelt.array_tools.pluralize('light')
#=> 'lights'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deprecation_caller_depth: nil, deprecation_strategy: nil, inflector: nil, messages_registry: nil) ⇒ Toolbelt

Returns a new instance of Toolbelt.

Parameters:

  • deprecation_caller_depth (Integer) (defaults to: nil)

    the number of backtrace lines to display when outputting a deprecation warning.

  • deprecation_strategy (String) (defaults to: nil)

    the name of the strategy used when deprecated code is called. Must be ‘ignore’, ‘raise’, or ‘warn’.

  • inflector (Object) (defaults to: nil)

    service object for inflecting strings. The inflector must be an object that conforms to the interface used by by SleepingKingStudios::Tools::Toolbox::Inflector, such as an instance of ActiveSupport::Inflector .

  • messages_registry (SleepingKingStudios::Tools::Messages::Registry) (defaults to: nil)

    the strategies registry to use for the tool. Defaults to the value of Registry.global.



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 44

def initialize(
  deprecation_caller_depth: nil,
  deprecation_strategy:     nil,
  inflector:                nil,
  messages_registry:        nil
)
  @deprecation_caller_depth = deprecation_caller_depth
  @deprecation_strategy     = deprecation_strategy
  @inflector                = inflector
  @messages_registry        = messages_registry
end

Class Method Details

.globalRegistry Also known as: instance

Returns a singleton instance of the messages registry, instantiating the instance if needed.

Returns:

  • (Registry)

    the messages registry singleton.



27
28
29
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 27

define_method :global do
  semaphore.synchronize { @global ||= new }
end

Instance Method Details

#array_toolsSleepingKingStudios::Tools::ArrayTools Also known as: ary

Returns tools for working with array-like enumerable objects.

Returns:



58
59
60
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 58

def array_tools
  @array_tools ||= ::SleepingKingStudios::Tools::ArrayTools.new(toolbelt:)
end

#assertionsSleepingKingStudios::Tools::Assertions

Returns methods for asserting on the state of a function or application.

Returns:



65
66
67
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 65

def assertions
  @assertions ||= ::SleepingKingStudios::Tools::Assertions.new(toolbelt:)
end

#core_toolsSleepingKingStudios::Tools::CoreTools

Returns tools for working with an application or working environment.

Returns:



71
72
73
74
75
76
77
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 71

def core_tools
  @core_tools ||= ::SleepingKingStudios::Tools::CoreTools.new(
    deprecation_caller_depth:,
    deprecation_strategy:,
    toolbelt:
  )
end

#hash_toolsSleepingKingStudios::Tools::HashTools Also known as: hsh

Returns tools for working with hash-like enumerable objects.

Returns:



81
82
83
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 81

def hash_tools
  @hash_tools ||= ::SleepingKingStudios::Tools::HashTools.new(toolbelt:)
end

#inspectString Also known as: to_s

Returns a human-readable representation of the object.

Returns:

  • (String)

    a human-readable representation of the object.



87
88
89
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 87

def inspect
  "#<#{::Object.instance_method(:class).bind(self).call.name}>"
end

#integer_toolsSleepingKingStudios::Tools::IntegerTools Also known as: int

Returns tools for working with integers.

Returns:



94
95
96
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 94

def integer_tools
  @integer_tools = ::SleepingKingStudios::Tools::IntegerTools.new(toolbelt:)
end

#messagesSleepingKingStudios::Tools::Messages

Returns methods for generating human-readable messages.

Returns:



101
102
103
104
105
106
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 101

def messages
  @messages ||= ::SleepingKingStudios::Tools::Messages.new(
    registry: messages_registry,
    toolbelt:
  )
end

#object_toolsSleepingKingStudios::Tools::ObjectTools Also known as: obj

Returns low-level tools for working with objects.

Returns:



110
111
112
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 110

def object_tools
  @object_tools ||= ::SleepingKingStudios::Tools::ObjectTools.new(toolbelt:)
end

#string_toolsSleepingKingStudios::Tools::ObjectTools Also known as: str

Returns tools for working with strings.

Returns:



117
118
119
120
121
122
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 117

def string_tools
  @string_tools ||= ::SleepingKingStudios::Tools::StringTools.new(
    inflector:,
    toolbelt:
  )
end