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'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deprecation_caller_depth: nil, deprecation_strategy: nil, inflector: 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 .



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 33

def initialize( # rubocop:disable Metrics/MethodLength
  deprecation_caller_depth: nil,
  deprecation_strategy:     nil,
  inflector:                nil
)
  @array_tools   = ::SleepingKingStudios::Tools::ArrayTools.new
  @assertions    = ::SleepingKingStudios::Tools::Assertions.new
  @core_tools    =
    ::SleepingKingStudios::Tools::CoreTools.new(
      deprecation_caller_depth:,
      deprecation_strategy:
    )
  @hash_tools    = ::SleepingKingStudios::Tools::HashTools.new
  @integer_tools = ::SleepingKingStudios::Tools::IntegerTools.new
  @object_tools  = ::SleepingKingStudios::Tools::ObjectTools.new
  @string_tools  =
    ::SleepingKingStudios::Tools::StringTools.new(inflector:)
end

Instance Attribute Details

#array_toolsSleepingKingStudios::Tools::ArrayTools (readonly) Also known as: ary

Returns tools for working with array-like enumerable objects.

Returns:



54
55
56
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 54

def array_tools
  @array_tools
end

#assertionsSleepingKingStudios::Tools::Assertions (readonly)

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

Returns:



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

def assertions
  @assertions
end

#core_toolsSleepingKingStudios::Tools::CoreTools (readonly)

Returns tools for working with an application or working environment.

Returns:



63
64
65
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 63

def core_tools
  @core_tools
end

#hash_toolsSleepingKingStudios::Tools::HashTools (readonly) Also known as: hsh

Returns tools for working with hash-like enumerable objects.

Returns:



67
68
69
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 67

def hash_tools
  @hash_tools
end

#integer_toolsSleepingKingStudios::Tools::IntegerTools (readonly) Also known as: int

Returns tools for working with integers.

Returns:



72
73
74
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 72

def integer_tools
  @integer_tools
end

#object_toolsSleepingKingStudios::Tools::ObjectTools (readonly) Also known as: obj

Returns low-level tools for working with objects.

Returns:



77
78
79
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 77

def object_tools
  @object_tools
end

#string_toolsSleepingKingStudios::Tools::ObjectTools (readonly) Also known as: str

Returns tools for working with strings.

Returns:



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

def string_tools
  @string_tools
end

Class Method Details

.instanceSleepingKingStudios::Tools::Toolbelt

Returns a memoized instance of the toolbelt class.

Returns:



21
22
23
# File 'lib/sleeping_king_studios/tools/toolbelt.rb', line 21

def self.instance
  @instance ||= new
end

Instance Method Details

#inspectString Also known as: to_s

Returns a human-readable representation of the object.

Returns:

  • (String)

    a human-readable representation of the object.



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

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