Class: Nazar::Formatter::ActiveRecordCollection
- Inherits:
-
Object
- Object
- Nazar::Formatter::ActiveRecordCollection
- Includes:
- ActiveRecordInterface
- Defined in:
- lib/nazar/formatter/active_record_collection.rb
Instance Attribute Summary
Attributes included from ActiveRecordInterface
#attributes, #collection, #klass
Class Method Summary collapse
-
.valid?(data) ⇒ Boolean
rubocop:disable Metrics/CyclomaticComplexity.
Instance Method Summary collapse
-
#initialize(collection) ⇒ ActiveRecordCollection
constructor
A new instance of ActiveRecordCollection.
- #summary ⇒ Object
Methods included from ActiveRecordInterface
Constructor Details
#initialize(collection) ⇒ ActiveRecordCollection
Returns a new instance of ActiveRecordCollection.
10 11 12 13 14 15 16 |
# File 'lib/nazar/formatter/active_record_collection.rb', line 10 def initialize(collection) @collection = collection @collection.load if @collection.respond_to?(:loaded?) && !@collection.loaded? @attributes = collection.first&.attributes @klass = collection.first&.class end |
Class Method Details
.valid?(data) ⇒ Boolean
rubocop:disable Metrics/CyclomaticComplexity
18 19 20 21 22 23 24 |
# File 'lib/nazar/formatter/active_record_collection.rb', line 18 def self.valid?(data) # rubocop:disable Metrics/CyclomaticComplexity return false if data.is_a?(::Struct) || (defined?(OpenStruct) && data.is_a?(OpenStruct)) data.is_a?(ActiveRecord::Associations::CollectionProxy) || data.is_a?(ActiveRecord::Relation) || (data.is_a?(Enumerable) && !data.is_a?(Range) && data.first.is_a?(ActiveRecord::Base)) end |
Instance Method Details
#summary ⇒ Object
26 27 28 |
# File 'lib/nazar/formatter/active_record_collection.rb', line 26 def summary collection.size end |