Class: SpreeBatchCapture::ScopeSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/spree_batch_capture/scope_serializer.rb

Class Method Summary collapse

Class Method Details

.from_scope(relation) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/spree_batch_capture/scope_serializer.rb', line 4

def self.from_scope(relation)
  raise "Invalid scope" unless relation.kind_of? ActiveRecord::Relation
  {
    :where => relation.where_values,
    :joins => relation.joins_values,
    :order => relation.order_values,
    :group => relation.group_values,
    :limit => relation.limit_value,
    :from  => relation.from_value,
    :select => relation.select_values,
    :includes => relation.includes_values,
    :having => relation.having_values,
    :offset_value => relation.offset_value,
  }
end

.to_scope(scope_hash) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/spree_batch_capture/scope_serializer.rb', line 20

def self.to_scope(scope_hash)
  scope_hash.symbolize_keys!
  return Order
    .where(scope_hash[:where])
    .joins(scope_hash[:joins])
    .order(scope_hash[:order])
    .group(scope_hash[:group])
    .limit(scope_hash[:limit])
    .from(scope_hash[:from])
    .select(scope_hash[:select])
    .includes(scope_hash[:includes])
    .having(scope_hash[:having])
    .offset(scope_hash[:offset])
end