Class: ActiveRecord::Relation
- Inherits:
-
Object
- Object
- ActiveRecord::Relation
- Defined in:
- lib/json_in_batches/core_ext.rb
Instance Method Summary collapse
-
#as_json(options = nil) ⇒ Object
:nodoc:.
Instance Method Details
#as_json(options = nil) ⇒ Object
:nodoc:
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/json_in_batches/core_ext.rb', line 3 def as_json( = nil) #:nodoc: # encode in batches only if there's no limit and order instructions, # because find_each ignores them if self.limit_value.nil? && self.orders.empty? # use encoder as a proxy to call as_json on all elements, to protect from circular references encoder = && [:encoder] || ActiveSupport::JSON::Encoding::Encoder.new() jsonified = [] find_each { |v| jsonified << encoder.as_json(v, ) } jsonified else to_a.as_json() end end |