sleeping_king_studios-tools 1.1.1 → 1.2.0.rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,17 @@ require 'sleeping_king_studios/tools'
4
4
 
5
5
  module SleepingKingStudios::Tools
6
6
  # Helper object for quick access to all available tools.
7
+ #
8
+ # Specific tools can be accessed by name. For example, to access the
9
+ # configured instance of ArrayTools, call Toolbelt#array_tools. Certain tools
10
+ # also define a shorthand - for example, the array_tools instance can also be
11
+ # accessed using Toolbelt#ary.
12
+ #
13
+ # @example
14
+ # toolbelt = SleepingKingStudios::Tools::Toolbelt.new
15
+ #
16
+ # toolbelt.array_tools.pluralize('light')
17
+ # #=> 'lights'
7
18
  class Toolbelt < BasicObject
8
19
  # @return [SleepingKingStudios::Tools::Toolbelt] a memoized instance of the
9
20
  # toolbelt class.
@@ -11,42 +22,64 @@ module SleepingKingStudios::Tools
11
22
  @instance ||= new
12
23
  end
13
24
 
14
- # @param deprecation_strategy [String] The name of the strategy used when
25
+ # @param deprecation_caller_depth [Integer] the number of backtrace lines to
26
+ # display when outputting a deprecation warning.
27
+ # @param deprecation_strategy [String] the name of the strategy used when
15
28
  # deprecated code is called. Must be 'ignore', 'raise', or 'warn'.
16
- # @param inflector [Object] An object that conforms to the interface used
17
- # by SleepingKingStudios::Tools::Toolbox::Inflector, such as
18
- # ActiveSupport::Inflector .
19
- def initialize(deprecation_strategy: nil, inflector: nil)
29
+ # @param inflector [Object] service object for inflecting strings. The
30
+ # inflector must be an object that conforms to the interface used by
31
+ # by SleepingKingStudios::Tools::Toolbox::Inflector, such as an instance
32
+ # of ActiveSupport::Inflector .
33
+ def initialize( # rubocop:disable Metrics/MethodLength
34
+ deprecation_caller_depth: nil,
35
+ deprecation_strategy: nil,
36
+ inflector: nil
37
+ )
20
38
  @array_tools = ::SleepingKingStudios::Tools::ArrayTools.new
21
39
  @assertions = ::SleepingKingStudios::Tools::Assertions.new
22
- @core_tools = ::SleepingKingStudios::Tools::CoreTools.new(
23
- deprecation_strategy: deprecation_strategy
24
- )
40
+ @core_tools =
41
+ ::SleepingKingStudios::Tools::CoreTools.new(
42
+ deprecation_caller_depth:,
43
+ deprecation_strategy:
44
+ )
25
45
  @hash_tools = ::SleepingKingStudios::Tools::HashTools.new
26
46
  @integer_tools = ::SleepingKingStudios::Tools::IntegerTools.new
27
47
  @object_tools = ::SleepingKingStudios::Tools::ObjectTools.new
28
48
  @string_tools =
29
- ::SleepingKingStudios::Tools::StringTools.new(inflector: inflector)
49
+ ::SleepingKingStudios::Tools::StringTools.new(inflector:)
30
50
  end
31
51
 
52
+ # @return [SleepingKingStudios::Tools::ArrayTools] tools for working with
53
+ # array-like enumerable objects.
32
54
  attr_reader :array_tools
55
+ alias ary array_tools
33
56
 
57
+ # @return [SleepingKingStudios::Tools::Assertions] methods for asserting on
58
+ # the state of a function or application.
34
59
  attr_reader :assertions
35
60
 
61
+ # @return [SleepingKingStudios::Tools::CoreTools] tools for working with an
62
+ # application or working environment.
36
63
  attr_reader :core_tools
37
64
 
65
+ # @return [SleepingKingStudios::Tools::HashTools] tools for working with
66
+ # hash-like enumerable objects.
38
67
  attr_reader :hash_tools
68
+ alias hsh hash_tools
39
69
 
70
+ # @return [SleepingKingStudios::Tools::IntegerTools] tools for working with
71
+ # integers.
40
72
  attr_reader :integer_tools
73
+ alias int integer_tools
41
74
 
75
+ # @return [SleepingKingStudios::Tools::ObjectTools] low-level tools for
76
+ # working with objects.
42
77
  attr_reader :object_tools
78
+ alias obj object_tools
43
79
 
80
+ # @return [SleepingKingStudios::Tools::ObjectTools] tools for working with
81
+ # strings.
44
82
  attr_reader :string_tools
45
-
46
- alias ary array_tools
47
- alias hsh hash_tools
48
- alias int integer_tools
49
- alias obj object_tools
50
83
  alias str string_tools
51
84
 
52
85
  # @return [String] a human-readable representation of the object.
@@ -7,11 +7,29 @@ require 'sleeping_king_studios/tools/toolbox'
7
7
 
8
8
  module SleepingKingStudios::Tools::Toolbox
9
9
  # Provides an enumerable interface for defining a group of constants.
10
+ #
11
+ # @example
12
+ # UserRoles = ConstantMap.new(
13
+ # {
14
+ # GUEST: 'guest',
15
+ # USER: 'user',
16
+ # ADMIN: 'admin'
17
+ # }
18
+ # )
19
+ #
20
+ # UserRoles::GUEST
21
+ # #=> 'guest'
22
+ #
23
+ # UserRoles.user
24
+ # #=> 'user'
25
+ #
26
+ # UserRoles.all
27
+ # #=> { :GUEST => 'guest', :USER => 'user', :ADMIN => 'admin' }
10
28
  class ConstantMap < Module
11
29
  extend Forwardable
12
30
  include Enumerable
13
31
 
14
- # @param constants [Hash] The constants to define.
32
+ # @param constants [Hash] the constants to define.
15
33
  def initialize(constants)
16
34
  super()
17
35
 
@@ -36,27 +54,27 @@ module SleepingKingStudios::Tools::Toolbox
36
54
  # Iterates through the defined constants, yielding the name and value of
37
55
  # each constant to the block.
38
56
  #
39
- # @yieldparam key [Symbol] The name of the constant.
40
- # @yieldparam value [Object] The value of the constant.
57
+ # @yieldparam key [Symbol] the name of the constant.
58
+ # @yieldparam value [Object] the value of the constant.
41
59
 
42
60
  # @!method each_key
43
61
  # Iterates through the defined constants, yielding the name of each
44
62
  # constant to the block.
45
63
  #
46
- # @yieldparam key [Symbol] The name of the constant.
64
+ # @yieldparam key [Symbol] the name of the constant.
47
65
 
48
66
  # @!method each_pair
49
67
  # Iterates through the defined constants, yielding the name and value of
50
68
  # each constant to the block.
51
69
  #
52
- # @yieldparam key [Symbol] The name of the constant.
53
- # @yieldparam value [Object] The value of the constant.
70
+ # @yieldparam key [Symbol] the name of the constant.
71
+ # @yieldparam value [Object] the value of the constant.
54
72
 
55
73
  # @!method each_value
56
74
  # Iterates through the defined constants, yielding the value of each
57
75
  # constant to the block.
58
76
  #
59
- # @yieldparam value [Object] The value of the constant.
77
+ # @yieldparam value [Object] the value of the constant.
60
78
 
61
79
  # @!method keys
62
80
  # @return [Array] the names of the defined constants.
@@ -68,10 +86,11 @@ module SleepingKingStudios::Tools::Toolbox
68
86
  attr_reader :to_h
69
87
  alias all to_h
70
88
 
71
- # Freezes the constant map and recursively freezes every constant value
72
- # using ObjectTools#deep_freeze.
89
+ # Freezes the constant map and recursively freezes every constant value.
73
90
  #
74
- # @see ObjectTools#deep_freeze
91
+ # @return [self] the constant map.
92
+ #
93
+ # @see SleepingKingStudios::Tools::ObjectTools#deep_freeze
75
94
  def freeze
76
95
  super
77
96
 
@@ -7,14 +7,13 @@ require 'sleeping_king_studios/tools/toolbox'
7
7
  class SleepingKingStudios::Tools::Toolbox::Inflector
8
8
  # Rules for inflecting words.
9
9
  class Rules
10
- # @param irregular_words [Hash<String, String>] Hash of irregular word
11
- # pairs in singular => plural order, e.g. "child" => "children".
12
- # @param plural_rules [Array<Array<(Regexp, String)>>] Rules for
10
+ # @param irregular_words [Hash<String, String>] irregular word pairs in
11
+ # singular => plural order, e.g. "child" => "children".
12
+ # @param plural_rules [Array<Array<(Regexp, String)>>] rules for
13
13
  # pluralizing words.
14
- # @param singular_rules [Array<Array<(Regexp, String)>>] Rules for
14
+ # @param singular_rules [Array<Array<(Regexp, String)>>] rules for
15
15
  # singularizing words.
16
- # @param uncountable_words [Array<String>] List of uncountable words,
17
- # e.g. "data".
16
+ # @param uncountable_words [Array<String>] uncountable words e.g. "data".
18
17
  def initialize(
19
18
  irregular_words: nil,
20
19
  plural_rules: nil,
@@ -30,29 +29,29 @@ class SleepingKingStudios::Tools::Toolbox::Inflector
30
29
  @irregular_words_reversed = reverse_hash(@irregular_words)
31
30
  end
32
31
 
33
- # @return [Array<Array<(String, String)>] Hash of irregular word pairs in
32
+ # @return [Array<Array<(String, String)>>] irregular word pairs in
34
33
  # singular => plural order.
35
34
  attr_reader :irregular_words
36
35
 
37
- # @return [Array<Array<(String, String)>] Hash of irregular word pairs in
38
- # plural => singular order.
36
+ # @return [Array<Array<(String, String)>>] irregular word pairs in plural =>
37
+ # singular order.
39
38
  attr_reader :irregular_words_reversed
40
39
 
41
- # @return [Array<Array<(Regexp, String)>>] Rules for pluralizing words.
40
+ # @return [Array<Array<(Regexp, String)>>] rules for pluralizing words.
42
41
  attr_reader :plural_rules
43
42
 
44
- # @return [Array<Array<(Regexp, String)>>] Rules for singularizing words.
43
+ # @return [Array<Array<(Regexp, String)>>] rules for singularizing words.
45
44
  attr_reader :singular_rules
46
45
 
47
- # @return [Array<String>] List of uncountable words.
46
+ # @return [Array<String>] uncountable words.
48
47
  attr_reader :uncountable_words
49
48
 
50
49
  # Defines an irregular word pair.
51
50
  #
52
- # @param singular [String] The singular form of the word.
53
- # @param plural [String] The plural form of the word.
51
+ # @param singular [String] the singular form of the word.
52
+ # @param plural [String] the plural form of the word.
54
53
  #
55
- # @return [Rules] The rules object.
54
+ # @return [self] the rules object.
56
55
  def define_irregular_word(singular, plural)
57
56
  validate_string(singular)
58
57
  validate_string(plural)
@@ -65,10 +64,10 @@ class SleepingKingStudios::Tools::Toolbox::Inflector
65
64
 
66
65
  # Defines a pluralization rule.
67
66
  #
68
- # @param pattern [Regexp] The pattern to match.
69
- # @param replace [String] The string to replace.
67
+ # @param pattern [Regexp] the pattern to match.
68
+ # @param replace [String] the string to replace.
70
69
  #
71
- # @return [Rules] The rules object.
70
+ # @return [self] the rules object.
72
71
  def define_plural_rule(pattern, replace)
73
72
  validate_pattern(pattern)
74
73
  validate_string(replace, as: 'replace')
@@ -80,10 +79,10 @@ class SleepingKingStudios::Tools::Toolbox::Inflector
80
79
 
81
80
  # Defines a singularization rule.
82
81
  #
83
- # @param pattern [Regexp] The pattern to match.
84
- # @param replace [String] The string to replace.
82
+ # @param pattern [Regexp] the pattern to match.
83
+ # @param replace [String] the string to replace.
85
84
  #
86
- # @return [Rules] The rules object.
85
+ # @return [self] the rules object.
87
86
  def define_singular_rule(pattern, replace)
88
87
  validate_pattern(pattern)
89
88
  validate_string(replace, as: 'replace')
@@ -95,9 +94,9 @@ class SleepingKingStudios::Tools::Toolbox::Inflector
95
94
 
96
95
  # Defines an uncountable word.
97
96
  #
98
- # @param word [String] The uncountable word.
97
+ # @param word [String] the uncountable word.
99
98
  #
100
- # @return [Rules] The rules object.
99
+ # @return [self] the rules object.
101
100
  def define_uncountable_word(word)
102
101
  validate_string(word)
103
102
 
@@ -106,7 +105,7 @@ class SleepingKingStudios::Tools::Toolbox::Inflector
106
105
  self
107
106
  end
108
107
 
109
- # @return [String] A human-readable representation of the rules object.
108
+ # @return [String] a human-readable representation of the rules object.
110
109
  def inspect
111
110
  "#<SleepingKingStudios::Tools::Toolbox::Inflector::Rules:#{object_id}>"
112
111
  end
@@ -5,9 +5,17 @@ require 'forwardable'
5
5
  require 'sleeping_king_studios/tools/toolbox'
6
6
 
7
7
  module SleepingKingStudios::Tools::Toolbox
8
- # Transforms words (e.g. from singular to plural).
8
+ # Service object for transforming strings.
9
9
  #
10
- # Should maintain the same interface as ActiveSupport::Inflector.
10
+ # Internally, an instance of this class is used to StringTools to perform
11
+ # string transformations.
12
+ #
13
+ # This class should define a compatible interface with
14
+ # ActiveSupport::Inflector, i.e. all methods defined on Toolbox::Inflector
15
+ # should have a corresponding method on ActiveSupport::Inflector with a
16
+ # superset of the parameters. (The reverse is *not* true).
17
+ #
18
+ # @see SleepingKingStudios::Tools::StringTools.
11
19
  class Inflector
12
20
  extend Forwardable
13
21
 
@@ -27,38 +35,41 @@ module SleepingKingStudios::Tools::Toolbox
27
35
  :singular_rules,
28
36
  :uncountable_words
29
37
 
30
- # @return [Rules] An object defining the transformation rules.
38
+ # @param rules [SleepingKingStudios::Tools::Toobox::Inflector::Rules] an
39
+ # object defining the transformation rules.
31
40
  def initialize(rules: nil)
32
41
  @rules = rules || Rules.new
33
42
  end
34
43
 
35
- # @return [Rules] The defined rules object for the inflector.
44
+ # @return [SleepingKingStudios::Tools::Toobox::Inflector::Rules] an object
45
+ # defining the transformation rules.
36
46
  attr_reader :rules
37
47
 
38
- # Transforms the word to CamelCase.
48
+ # Converts a lowercase, underscore-separated string to CamelCase.
39
49
  #
40
- # @param word [String] The word to transform.
41
- # @param uppercase_first_letter [Boolean] If true, the first letter is
50
+ # @param word [String] the word to transform.
51
+ # @param uppercase_first_letter [Boolean] if true, the first letter is
42
52
  # capitalized. Defaults to true.
43
53
  #
44
- # @return [String] The word in CamelCase.
54
+ # @return [String] the word in CamelCase.
45
55
  def camelize(word, uppercase_first_letter = true) # rubocop:disable Style/OptionalBooleanParameter
46
56
  return '' if word.nil? || word.empty?
47
57
 
48
- word = word.to_s.gsub(/(\b|[_-])([a-z])/) { Regexp.last_match(2).upcase }
58
+ word =
59
+ word
60
+ .to_s
61
+ .gsub(/(\b|[_-]+)([a-z])/) { Regexp.last_match(2).upcase }
62
+ .gsub(/[_-]+/, '')
49
63
 
50
64
  (uppercase_first_letter ? word[0].upcase : word[0].downcase) + word[1..]
51
65
  end
52
66
 
53
- # rubocop:disable Metrics/AbcSize
54
- # rubocop:disable Metrics/CyclomaticComplexity
55
-
56
67
  # Transforms the word to a plural, lowercase form.
57
68
  #
58
- # @param word [String] The word to transform.
69
+ # @param word [String] the word to transform.
59
70
  #
60
- # @return [String] The word in plural form.
61
- def pluralize(word)
71
+ # @return [String] the word in plural form.
72
+ def pluralize(word) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
62
73
  return '' if word.nil? || word.empty?
63
74
 
64
75
  normalized = word.to_s.strip.downcase
@@ -77,14 +88,12 @@ module SleepingKingStudios::Tools::Toolbox
77
88
 
78
89
  word
79
90
  end
80
- # rubocop:enable Metrics/AbcSize
81
- # rubocop:enable Metrics/CyclomaticComplexity
82
91
 
83
92
  # Transforms the word to a singular, lowercase form.
84
93
  #
85
- # @param word [String] The word to transform.
94
+ # @param word [String] the word to transform.
86
95
  #
87
- # @return [String] The word in singular form.
96
+ # @return [String] the word in singular form.
88
97
  def singularize(word) # rubocop:disable Metrics/MethodLength
89
98
  return '' if word.nil? || word.empty?
90
99
 
@@ -109,16 +118,17 @@ module SleepingKingStudios::Tools::Toolbox
109
118
  #
110
119
  # @param word [String] the word to transform.
111
120
  #
112
- # @return [String] The word in underscored form.
121
+ # @return [String] the word in underscored form.
113
122
  def underscore(word)
114
123
  return '' if word.nil? || word.empty?
115
124
 
116
- word = word.to_s.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
117
-
118
- word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
119
- word.tr!('-', '_')
120
- word.downcase!
121
125
  word
126
+ .to_s
127
+ .gsub(/([A-Z0-9\d]+)([A-Z][a-z])/, '\1_\2')
128
+ .gsub(/([a-z\d])([A-Z0-9])/, '\1_\2')
129
+ .gsub(/\A_+|_+\z/, '')
130
+ .tr('-', '_')
131
+ .downcase
122
132
  end
123
133
  end
124
134
  end
@@ -4,26 +4,98 @@ require 'sleeping_king_studios/tools/toolbox'
4
4
 
5
5
  module SleepingKingStudios::Tools::Toolbox
6
6
  # Implements recursive inheritance of both class and instance methods.
7
+ #
8
+ # @example Defining A Mixin
9
+ # module Widgets
10
+ # extend SleepingKingStudios::Tools::Toolbox::Mixin
11
+ #
12
+ # module ClassMethods
13
+ # def widget_types
14
+ # %w(gadget doohickey thingamabob)
15
+ # end
16
+ # end
17
+ #
18
+ # def widget?(widget_type)
19
+ # self.class.widget_types.include?(widget_type)
20
+ # end
21
+ # end
22
+ #
23
+ # @example Including A Mixin
24
+ # module WidgetBuilding
25
+ # extend SleepingKingStudios::Tools::Toolbox::Mixin
26
+ # include Widgets
27
+ #
28
+ # def build_widget(widget_type)
29
+ # raise ArgumentError, 'not a widget', caller unless widget?(widget_type)
30
+ #
31
+ # Widget.new(widget_type)
32
+ # end
33
+ # end
34
+ #
35
+ # @example Using A Mixin
36
+ # class WidgetFactory
37
+ # include WidgetBuilding
38
+ # end
39
+ #
40
+ # factory = WidgetFactory.new
41
+ #
42
+ # factory.build_widget('gadget')
43
+ # #=> Widget
44
+ #
45
+ # WidgetFactory.widget_types
46
+ # #=> ['gadget', 'doohickey', 'thingamabob']
7
47
  module Mixin
8
- # @api private
9
- def self.mixin?(mod)
10
- return false unless mod.is_a?(Module)
48
+ # Checks if the given module is itself a Mixin.
49
+ #
50
+ # @param othermod [Object] the object or module to inspect.
51
+ #
52
+ # @return [true, false] true if the other object is a Module that extends
53
+ # Mixin; otherwise false.
54
+ def self.mixin?(othermod)
55
+ return false unless othermod.is_a?(Module)
11
56
 
12
- mod.singleton_class.include?(self)
57
+ othermod.singleton_class.include?(self)
13
58
  end
14
59
 
15
- # @private
16
- def included(other)
60
+ # Callback invoked whenever the receiver is included in another module.
61
+ #
62
+ # @param othermod [Module] the other class or module in which the mixin is
63
+ # included.
64
+ #
65
+ # @return [void]
66
+ def included(othermod)
17
67
  return super unless defined?(self::ClassMethods)
18
68
 
19
- if SleepingKingStudios::Tools::Toolbox::Mixin.mixin?(other)
20
- unless other.constants(false).include?(:ClassMethods)
21
- other.const_set(:ClassMethods, Module.new)
69
+ if SleepingKingStudios::Tools::Toolbox::Mixin.mixin?(othermod)
70
+ unless othermod.constants(false).include?(:ClassMethods)
71
+ othermod.const_set(:ClassMethods, Module.new)
22
72
  end
23
73
 
24
- other::ClassMethods.include(self::ClassMethods)
74
+ othermod::ClassMethods.include(self::ClassMethods)
25
75
  else
26
- other.extend self::ClassMethods
76
+ othermod.extend self::ClassMethods
77
+ end
78
+
79
+ super
80
+ end
81
+
82
+ # Callback invoked whenever the receiver is prepended into another module.
83
+ #
84
+ # @param othermod [Module] the other class or module in which the mixin is
85
+ # prepended.
86
+ #
87
+ # @return [void]
88
+ def prepended(othermod)
89
+ return super unless defined?(self::ClassMethods)
90
+
91
+ if SleepingKingStudios::Tools::Toolbox::Mixin.mixin?(othermod)
92
+ unless othermod.constants(false).include?(:ClassMethods)
93
+ othermod.const_set(:ClassMethods, Module.new)
94
+ end
95
+
96
+ othermod::ClassMethods.prepend(self::ClassMethods)
97
+ else
98
+ othermod.singleton_class.prepend(self::ClassMethods)
27
99
  end
28
100
 
29
101
  super
@@ -3,8 +3,7 @@
3
3
  require 'sleeping_king_studios/tools/toolbox'
4
4
 
5
5
  module SleepingKingStudios::Tools::Toolbox
6
- # Helper for generating semantic version strings with optional prerelease and
7
- # build parameters.
6
+ # Helper for generating semantic version strings.
8
7
  #
9
8
  # @example
10
9
  # module Version
@@ -15,15 +14,24 @@ module SleepingKingStudios::Tools::Toolbox
15
14
  # PATCH = 4
16
15
  # PRERELEASE = 'beta'
17
16
  # BUILD = 1
18
- # end # module
17
+ # end
18
+ #
19
+ # VERSION = Version.to_version
20
+ # #=> '3.1.4-beta+1'
19
21
  #
20
22
  # VERSION = Version.to_gem_version
23
+ # #=> '3.1.4.beta.1'
21
24
  #
22
25
  # @see http://semver.org
23
26
  module SemanticVersion
27
+ UNDEFINED = Object.new.freeze
28
+ private_constant :UNDEFINED
29
+
24
30
  # Error class for handling missing constants in a version definition.
25
31
  class InvalidVersionError < StandardError; end
26
32
 
33
+ # Generates a RubyGems-compatible version string.
34
+ #
27
35
  # Concatenates the MAJOR, MINOR, and PATCH constant values with PRERELEASE
28
36
  # and BUILD (if available) to generate a modified semantic version string
29
37
  # compatible with Rubygems. The major, minor, patch, prerelease, and build
@@ -38,16 +46,17 @@ module SleepingKingStudios::Tools::Toolbox
38
46
  # PATCH = 4
39
47
  # PRERELEASE = 'beta'
40
48
  # BUILD = 1
41
- # end # module
49
+ # end
42
50
  #
43
51
  # VERSION = Version.to_gem_version
44
52
  # #=> '3.1.4.beta.1'
45
53
  #
46
- # @return [String] The modified semantic version string.
54
+ # @return [String] the modified semantic version string.
47
55
  #
48
- # @raise InvalidVersionError If MAJOR, MINOR, or PATCH is undefined.
56
+ # @raise [SleepingKingStudios::Tools::Toolbox::SemanticVersion::InvalidVersionError]
57
+ # if MAJOR, MINOR, or PATCH is undefined.
49
58
  def to_gem_version
50
- str = +"#{const_fetch :MAJOR}.#{const_fetch :MINOR}.#{const_fetch :PATCH}"
59
+ str = "#{const_fetch :MAJOR}.#{const_fetch :MINOR}.#{const_fetch :PATCH}"
51
60
 
52
61
  prerelease = const_fetch(:PRERELEASE, nil)
53
62
  str << ".#{prerelease}" unless prerelease.nil? || prerelease.empty?
@@ -58,6 +67,8 @@ module SleepingKingStudios::Tools::Toolbox
58
67
  str
59
68
  end
60
69
 
70
+ # Generates a standard Semver version string.
71
+ #
61
72
  # Concatenates the MAJOR, MINOR, and PATCH constant values with PRERELEASE
62
73
  # and BUILD (if available) to generate a semantic version string. The
63
74
  # major, minor, and patch values are separated by dots (.), then the
@@ -73,16 +84,17 @@ module SleepingKingStudios::Tools::Toolbox
73
84
  # PATCH = 4
74
85
  # PRERELEASE = 'beta'
75
86
  # BUILD = 1
76
- # end # module
87
+ # end
77
88
  #
78
89
  # VERSION = Version.to_version
79
90
  # #=> '3.1.4-beta+1'
80
91
  #
81
- # @return [String] The semantic version string.
92
+ # @return [String] the semantic version string.
82
93
  #
83
- # @raise InvalidVersionError If MAJOR, MINOR, or PATCH is undefined.
94
+ # @raise [SleepingKingStudios::Tools::Toolbox::SemanticVersion::InvalidVersionError]
95
+ # if MAJOR, MINOR, or PATCH is undefined.
84
96
  def to_version
85
- str = +"#{const_fetch :MAJOR}.#{const_fetch :MINOR}.#{const_fetch :PATCH}"
97
+ str = "#{const_fetch :MAJOR}.#{const_fetch :MINOR}.#{const_fetch :PATCH}"
86
98
 
87
99
  prerelease = const_fetch(:PRERELEASE, nil)
88
100
  str << "-#{prerelease}" unless prerelease.nil? || prerelease.empty?
@@ -95,12 +107,10 @@ module SleepingKingStudios::Tools::Toolbox
95
107
 
96
108
  private
97
109
 
98
- FETCH_DEFAULT = Object.new.freeze
99
-
100
- def const_fetch(name, default = FETCH_DEFAULT)
110
+ def const_fetch(name, default = UNDEFINED)
101
111
  return const_get(name).to_s if const_defined?(name)
102
112
 
103
- return nil unless default == FETCH_DEFAULT
113
+ return nil unless default == UNDEFINED
104
114
 
105
115
  raise InvalidVersionError,
106
116
  "undefined constant for #{name.downcase} version"
@@ -24,14 +24,14 @@ module SleepingKingStudios::Tools::Toolbox
24
24
  module Subclass
25
25
  # Creates a subclass with partially applied constructor parameters.
26
26
  #
27
- # @param class_arguments [Array] The arguments, if any, to apply to the
27
+ # @param class_arguments [Array] the arguments, if any, to apply to the
28
28
  # constructor. These arguments will be added before any args passed
29
29
  # directly to the constructor.
30
- # @param class_keywords [Hash] The keywords, if any, to apply to the
30
+ # @param class_keywords [Hash] the keywords, if any, to apply to the
31
31
  # constructor. These keywords will be added before any kwargs passed
32
32
  # directly to the constructor.
33
33
  #
34
- # @yield The block, if any, to pass to the constructor. This will be
34
+ # @yield the block, if any, to pass to the constructor. This will be
35
35
  # overriden by a block passed directly to the constructor.
36
36
  #
37
37
  # @return [Class] the generated subclass.
@@ -44,7 +44,7 @@ module SleepingKingStudios::Tools::Toolbox
44
44
  *args,
45
45
  **class_keywords,
46
46
  **kwargs,
47
- &(block || class_block)
47
+ &(block || class_block) # rubocop:disable Style/RedundantParentheses
48
48
  )
49
49
  end
50
50
 
@@ -3,9 +3,7 @@
3
3
  require 'sleeping_king_studios/tools'
4
4
 
5
5
  module SleepingKingStudios::Tools
6
- # Namespace for common objects or patterns that are useful across projects but
7
- # are larger than or do not fit the functional paradigm of the tools.*
8
- # pattern.
6
+ # Namespace for defining common objects outside the tools.* pattern.
9
7
  module Toolbox
10
8
  autoload :ConstantMap,
11
9
  'sleeping_king_studios/tools/toolbox/constant_map'
@@ -13,13 +13,13 @@ module SleepingKingStudios
13
13
  # Major version.
14
14
  MAJOR = 1
15
15
  # Minor version.
16
- MINOR = 1
16
+ MINOR = 2
17
17
  # Patch version.
18
- PATCH = 1
18
+ PATCH = 0
19
19
  # Prerelease version.
20
- PRERELEASE = nil
20
+ PRERELEASE = :rc
21
21
  # Build metadata.
22
- BUILD = nil
22
+ BUILD = 0
23
23
  end
24
24
 
25
25
  # The current version of the gem.