Module: ActiveRecordExtension

Extended by:
ActiveSupport::Concern
Defined in:
lib/relational_exporter/active_record_extension.rb

Instance Method Summary collapse

Instance Method Details

#clear_default_scopesObject



33
34
35
# File 'lib/relational_exporter/active_record_extension.rb', line 33

def clear_default_scopes
  self.default_scopes = []
end

#find_all_by_scope(scope_hash = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/relational_exporter/active_record_extension.rb', line 4

def find_all_by_scope(scope_hash={})
  scope_hash = { where: {} } if scope_hash.nil?
  the_scope = nil
  scope_hash.each do |method, scoping|
    if the_scope.nil?
      the_scope = send method.to_sym, scoping
    else
      the_scope.send method.to_sym, scoping
    end
  end
  the_scope
end

#set_scope_from_hash(scope_hash = {}, clear_default_scope = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/relational_exporter/active_record_extension.rb', line 17

def set_scope_from_hash(scope_hash={}, clear_default_scope=false)
  scope_hash = {} if scope_hash.nil?
  clear_default_scopes if clear_default_scope

  result = nil
  scope_hash.each do |method, scoping|
    if result.nil?
      result = send method.to_sym, scoping
    else
      result.send method.to_sym, scoping
    end
  end

  default_scope { result }
end