class ObjectIdentifier::Parameters
ObjectIdentifier::Parameters
encapsulates the attributes list and formatter options that may be needed for custom formatting during object identification.
Constants
- CLASS_NOT_GIVEN
-
This String to display if ‘formatter_options` isn’t present.
Attributes
Public Class Methods
Source
# File lib/object_identifier/parameters.rb, line 15 def self.build(attributes: [], formatter_options: {}) attrs = ObjectIdentifier::ArrayWrap.(attributes) attrs = ObjectIdentifier.default_attributes if attrs.empty? attrs.flatten! new( attributes: attrs, formatter_options: formatter_options.to_h) end
Factory method for building an {ObjectIdentifier::Parameters} object. Uses ObjectIdentifier.default_attributes
if the given ‘attributes` array is empty.
Source
# File lib/object_identifier/parameters.rb, line 31 def initialize( # rubocop:disable Metrics/MethodLength attributes: [], formatter_options: {}) @attributes = attributes @limit = formatter_options.fetch(:limit, nil) @class = formatter_options.fetch(:class) { # For backwards compatibility with earlier versions of this gem. if formatter_options.key?(:klass) warn( "DEPRECATION WARNING: "\ "The `klass` option is deprecated and will be removed in v1.0. "\ "Use `class` instead.") formatter_options[:klass] else CLASS_NOT_GIVEN end } end
@param attributes [Array, *args] A list of method calls to interrogate the
given object(s) with.
@option formatter_options [Integer, nil] A given limit on the number
of objects to interrogate.
@option formatter_options [#to_s] A preferred type name for
identifying the given object(s) as.
Public Instance Methods
Source
# File lib/object_identifier/parameters.rb, line 57 def class if class_given? @class.to_s elsif block_given? yield.to_s else nil end end
NOTE: Expects a block if a value wasn’t supplied on initialization.
Source
# File lib/object_identifier/parameters.rb, line 52 def limit @limit || (yield if block_given?) end
NOTE: Expects a block if a value wasn’t supplied on initialization.
Private Instance Methods
Source
# File lib/object_identifier/parameters.rb, line 69 def class_given? @class != CLASS_NOT_GIVEN end