Class: SBF::Client::EntityCollection
- Includes:
- EntityResponseConcern
- Defined in:
- lib/stbaldricks/entities/lib/collection.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Instance Method Summary collapse
-
#[](*args) ⇒ Object
rubocop:disable Style/MultipleComparison.
-
#error ⇒ Object
Attempt to return an ErrorEntity similar to or exactly like the original.
-
#initialize(entities = [], total_count = 0, errors = nil) ⇒ EntityCollection
constructor
A new instance of EntityCollection.
Methods included from EntityResponseConcern
#add_errors, #data, #error?, #errors?, #errors_http_code=, #http_code, #success?
Methods inherited from Array
Constructor Details
#initialize(entities = [], total_count = 0, errors = nil) ⇒ EntityCollection
Returns a new instance of EntityCollection.
10 11 12 13 14 |
# File 'lib/stbaldricks/entities/lib/collection.rb', line 10 def initialize(entities = [], total_count = 0, errors = nil) concat(entities) @total_count = total_count @errors = errors || SBF::Client::Entity::Errors.new(self) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/stbaldricks/entities/lib/collection.rb', line 8 def errors @errors end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
7 8 9 |
# File 'lib/stbaldricks/entities/lib/collection.rb', line 7 def total_count @total_count end |
Instance Method Details
#[](*args) ⇒ Object
rubocop:disable Style/MultipleComparison
31 32 33 34 35 36 37 38 |
# File 'lib/stbaldricks/entities/lib/collection.rb', line 31 def [](*args) log_deprecated('[]', caller) if args == [:results] || args == [:total_count] return self if args == [:results] return @total_count if args == [:total_count] result = super result.is_a?(Array) ? self.class.new(result, total_count) : result end |
#error ⇒ Object
Attempt to return an ErrorEntity similar to or exactly like the original
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/stbaldricks/entities/lib/collection.rb', line 19 def error log_deprecated('error', caller) return nil if single_active_model_error.nil? details = single_active_model_error.find { |x| x.is_a?(String) } if single_active_model_error.is_a?(Array) details ||= single_active_model_error.is_a?(String) ? single_active_model_error : '' details = details["#{errors.type}: ".length..(details.length - 1)] if details.start_with?("#{errors.type}: ") SBF::Client::ErrorEntity.new(code: errors.code, type: errors.type, details: details) end |