Class: Workarea::AdminQueryOperation
- Inherits:
-
Object
- Object
- Workarea::AdminQueryOperation
- Includes:
- Enumerable
- Defined in:
- app/queries/workarea/admin_query_operation.rb
Instance Attribute Summary collapse
-
#exclude_ids ⇒ Object
readonly
Returns the value of attribute exclude_ids.
-
#ids ⇒ Object
readonly
Returns the value of attribute ids.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#query_id ⇒ Object
readonly
Returns the value of attribute query_id.
Instance Method Summary collapse
- #count ⇒ Object
- #each ⇒ Object
-
#initialize(options = {}) ⇒ AdminQueryOperation
constructor
A new instance of AdminQueryOperation.
- #query ⇒ Object
- #use_query? ⇒ Boolean
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 = .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_ids ⇒ Object (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 |
#ids ⇒ Object (readonly)
Returns the value of attribute ids.
5 6 7 |
# File 'app/queries/workarea/admin_query_operation.rb', line 5 def ids @ids end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'app/queries/workarea/admin_query_operation.rb', line 5 def @options end |
#query_id ⇒ Object (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
#count ⇒ Object
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 |
#each ⇒ Object
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 |
#query ⇒ Object
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!() end end |
#use_query? ⇒ Boolean
29 30 31 |
# File 'app/queries/workarea/admin_query_operation.rb', line 29 def use_query? ids.blank? end |