Skip to content

Commit

Permalink
Small documentation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul DobbinSchmaltz committed Nov 18, 2023
1 parent 86a6584 commit 6e05d5e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
12 changes: 9 additions & 3 deletions lib/object_identifier.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

# ObjectIdentifier is the base namespace for all modules/classes related to the
# object_identifier gem.
# ObjectIdentifier is the top-level namespace/module for this gem.
module ObjectIdentifier
# :reek:LongParameterList

# ObjectIdentifier.call is the main entry point for use of this gem. In
# typical usage, however, this method will almost exclusively just be called
# by {Object#identify}, as defined in lib/core_ext/object.rb.
# :reek:LongParameterList
def self.call(
objects,
*attributes,
Expand Down Expand Up @@ -80,8 +80,14 @@ def default_attributes=(value)
require "object_identifier/version"
require "object_identifier/array_wrap"
require "object_identifier/parameters"

# FORMATTERS

require "object_identifier/formatters/base_formatter"
require "object_identifier/formatters/string_formatter"

# CORE EXTENSIONS

require "core_ext/object"
require "core_ext/string"
require "core_ext/symbol"
Expand Down
4 changes: 4 additions & 0 deletions lib/object_identifier/array_wrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
class ObjectIdentifier::ArrayWrap
# :reek:NilCheck
# :reek:ManualDispatch

# Dispatch "Array Wrapping" logic on the given `object`.
#
# @param object The object(s) to attempt to Array wrap.
def self.call(object)
if object.nil?
[]
Expand Down
4 changes: 2 additions & 2 deletions lib/object_identifier/formatters/base_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def self.call(...)
new(...).call
end

# @param objects [Object, [Object, ...]] the object(s) to be interrogated for
# String values to be added to the output String
# @param objects [Object, [Object, ...]] The object(s) to be interrogated for
# String values to be added to the output String.
# @param parameters [ObjectIdentifier::Parameters]
def initialize(objects, parameters: ObjectIdentifier::Parameters.build)
@objects = ObjectIdentifier::ArrayWrap.(objects)
Expand Down
17 changes: 10 additions & 7 deletions lib/object_identifier/formatters/string_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# ObjectIdentifier::StringFormatter builds a String to identify the
# given object(s).
class ObjectIdentifier::StringFormatter < ObjectIdentifier::BaseFormatter
# The String to output when the {#objects} is empty.
# The String to output when {#objects} is empty.
NO_OBJECTS_INDICATOR = "[no objects]"

# Output the self-identifying string for the given object(s). Will either
# return a single object representation or a list of object
# representations, based on the number of objects we're identifying.
#
# @return [String] a string that identifies the object(s)
# @return [String] A string that identifies the object(s).
def call
if objects.none?
NO_OBJECTS_INDICATOR
Expand Down Expand Up @@ -85,15 +85,15 @@ class Item
attr_reader :object,
:parameters

# @param object [Object] the object to be interrogated for String values to
# be added to the output String
# @param object [Object] The object to be interrogated for String values to
# be added to the output String.
# @param parameters [ObjectIdentifier::Parameters]
def initialize(object, parameters)
@object = object
@parameters = parameters
end

# @return [String] the self-identifying String for {object}.
# @return [String] The self-identifying String for {#object}.
def call
return NO_OBJECTS_INDICATOR if blank?

Expand All @@ -102,8 +102,9 @@ def call

private

# Simple version of Rails' Object#blank? method.
# :reek:NilCheck

# Simple version of Rails' Object#blank? method.
def blank?
object.nil? || object == [] || object == {}
end
Expand All @@ -117,6 +118,7 @@ def formatted_attributes
end

# :reek:DuplicateMethodCall

def attributes_formatter
@attributes_formatter ||=
if attributes_hash.one?
Expand All @@ -126,8 +128,9 @@ def attributes_formatter
end
end

# @return [Hash]
# :reek:ManualDispatch

# @return [Hash]
def attributes_hash
@attributes_hash ||=
attributes.each_with_object({}) { |key, acc|
Expand Down
12 changes: 6 additions & 6 deletions lib/object_identifier/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def self.build(attributes: [], formatter_options: {})
formatter_options: formatter_options.to_h)
end

# @param attributes [Array, *args] a list of method calls to interrogate the
# given object(s) with
# @option formatter_options[:limit] [Integer, nil] (nil) a given limit on the
# number of objects to interrogate
# @option formatter_options[:klass] [#to_s] a preferred type name for
# identifying the given object(s) as
# @param attributes [Array, *args] A list of method calls to interrogate the
# given object(s) with.
# @option formatter_options[:limit] [Integer, nil] A given limit on the number
# of objects to interrogate.
# @option formatter_options[:klass] [#to_s] A preferred type name for
# identifying the given object(s) as.
def initialize(
attributes: [],
formatter_options: {})
Expand Down

0 comments on commit 6e05d5e

Please sign in to comment.