Module: Surrealist::Helper

Defined in:
lib/surrealist/helper.rb

Overview

A generic helper.

Class Method Summary collapse

Class Method Details

.collection?(object) ⇒ Boolean

Returns:

  • (Boolean)

15
16
17
18
19
20
21
22
# 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) ⇒ Boolean

Determines if the class uses the Surrealist mixin.

Parameters:

  • klass (Class)

    a class to be checked.

Returns:

  • (Boolean)

    if Surrealist is included in class.


11
12
13
# File 'lib/surrealist/helper.rb', line 11

def self.surrealist?(klass)
  klass < Surrealist || klass < Surrealist::Serializer
end