Class: ObjectIdentifier::Parameters
- Defined in:
- lib/object_identifier/parameters.rb
Overview
ObjectIdentifier::Parameters encapsulates the attributes list and formatter options that may be needed for custom formatting during object identification.
Constant Summary collapse
- CLASS_NOT_GIVEN =
This String to display if ‘formatter_options` isn’t present.
"NOT_GIVEN"
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
-
.build(attributes: [], formatter_options: {}) ⇒ Object
Factory method for building an Parameters object.
Instance Method Summary collapse
-
#class ⇒ Object
NOTE: Expects a block if a value wasn’t supplied on initialization.
-
#initialize(attributes: [], formatter_options: {}) ⇒ Parameters
constructor
A new instance of Parameters.
-
#limit ⇒ Object
NOTE: Expects a block if a value wasn’t supplied on initialization.
Constructor Details
#initialize(attributes: [], formatter_options: {}) ⇒ Parameters
Returns a new instance of Parameters.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/object_identifier/parameters.rb', line 31 def initialize( # rubocop:disable Metrics/MethodLength attributes: [], formatter_options: {}) @attributes = attributes @limit = .fetch(:limit, nil) @class = .fetch(:class) { # For backwards compatibility with earlier versions of this gem. if .key?(:klass) warn( "DEPRECATION WARNING: "\ "The `klass` option is deprecated and will be removed in v1.0. "\ "Use `class` instead.") [:klass] else CLASS_NOT_GIVEN end } end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
10 11 12 |
# File 'lib/object_identifier/parameters.rb', line 10 def attributes @attributes end |
Class Method Details
.build(attributes: [], formatter_options: {}) ⇒ Object
Factory method for building an ObjectIdentifier::Parameters object. Uses ObjectIdentifier.default_attributes if the given ‘attributes` array is empty.
15 16 17 18 19 20 21 22 23 |
# 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: .to_h) end |
Instance Method Details
#class ⇒ Object
NOTE: Expects a block if a value wasn’t supplied on initialization.
57 58 59 60 61 62 63 64 65 |
# 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 |
#limit ⇒ Object
NOTE: Expects a block if a value wasn’t supplied on initialization.
52 53 54 |
# File 'lib/object_identifier/parameters.rb', line 52 def limit @limit || (yield if block_given?) end |