module Surrealist::Helper

A generic helper.

Public Class Methods

collection?(object) click to toggle source
# File lib/surrealist/helper.rb, line 15
def self.collection?(object)
  # 4.2 AR relation object did not include Enumerable (it defined
  # all necessary method through ActiveRecord::Delegation module),
  # so we need to explicitly check for this
  return false if object.is_a?(Struct)

  object.is_a?(Enumerable) && !object.instance_of?(Hash) || ar_relation?(object)
end
surrealist?(klass) click to toggle source

Determines if the class uses the Surrealist mixin.

@param [Class] klass a class to be checked.

@return [Boolean] if Surrealist is included in class.

# File lib/surrealist/helper.rb, line 11
def self.surrealist?(klass)
  klass < Surrealist || klass < Surrealist::Serializer
end

Private Class Methods

ar_relation?(object) click to toggle source
# File lib/surrealist/helper.rb, line 24
def self.ar_relation?(object)
  defined?(ActiveRecord) && object.is_a?(ActiveRecord::Relation)
end