Class: Workarea::AdminQueryOperation

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
app/queries/workarea/admin_query_operation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AdminQueryOperation

Returns a new instance of AdminQueryOperation.



8
9
10
11
12
13
# File 'app/queries/workarea/admin_query_operation.rb', line 8

def initialize(options = {})
  @options = options.with_indifferent_access
  @query_id = @options[:query_id]
  @ids = Array.wrap(@options[:ids])
  @exclude_ids = Array.wrap(@options[:exclude_ids])
end

Instance Attribute Details

#exclude_idsObject (readonly)

Returns the value of attribute exclude_ids.



5
6
7
# File 'app/queries/workarea/admin_query_operation.rb', line 5

def exclude_ids
  @exclude_ids
end

#idsObject (readonly)

Returns the value of attribute ids.



5
6
7
# File 'app/queries/workarea/admin_query_operation.rb', line 5

def ids
  @ids
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'app/queries/workarea/admin_query_operation.rb', line 5

def options
  @options
end

#query_idObject (readonly)

Returns the value of attribute query_id.



5
6
7
# File 'app/queries/workarea/admin_query_operation.rb', line 5

def query_id
  @query_id
end

Instance Method Details

#countObject



21
22
23
24
25
26
27
# File 'app/queries/workarea/admin_query_operation.rb', line 21

def count
  if ids.any?
    (ids - exclude_ids).size
  else
    query.total - exclude_ids.size
  end
end

#eachObject



33
34
35
36
37
38
39
40
41
42
43
# File 'app/queries/workarea/admin_query_operation.rb', line 33

def each
  if use_query?
    create_query_to_perform_with.scroll do |results|
      results.each { |model| yield(model) unless exclude?(model) }
    end
  else
    GlobalID::Locator.locate_many(ids).each do |model|
      yield(model) unless exclude?(model)
    end
  end
end

#queryObject



15
16
17
18
19
# File 'app/queries/workarea/admin_query_operation.rb', line 15

def query
  @query ||= GlobalID.find(query_id).tap do |query|
    query.params.merge!(options)
  end
end

#use_query?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/queries/workarea/admin_query_operation.rb', line 29

def use_query?
  ids.blank?
end