Class: WorkerPlugins::RemoveCollection
- Inherits:
-
ApplicationService
- Object
- ServicePattern::Service
- ApplicationService
- WorkerPlugins::RemoveCollection
- Defined in:
- app/services/worker_plugins/remove_collection.rb
Instance Attribute Summary collapse
-
#destroyed ⇒ Object
readonly
Returns the value of attribute destroyed.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#workplace ⇒ Object
readonly
Returns the value of attribute workplace.
Instance Method Summary collapse
-
#initialize(query:, workplace:) ⇒ RemoveCollection
constructor
A new instance of RemoveCollection.
- #model_class ⇒ Object
- #perform ⇒ Object
- #query_with_selected_ids ⇒ Object
- #remove_query_from_workplace ⇒ Object
Methods inherited from ApplicationService
#db_now_value, #postgres?, #quote, #sqlite?
Constructor Details
#initialize(query:, workplace:) ⇒ RemoveCollection
Returns a new instance of RemoveCollection.
4 5 6 7 |
# File 'app/services/worker_plugins/remove_collection.rb', line 4 def initialize(query:, workplace:) @query = query @workplace = workplace end |
Instance Attribute Details
#destroyed ⇒ Object (readonly)
Returns the value of attribute destroyed.
2 3 4 |
# File 'app/services/worker_plugins/remove_collection.rb', line 2 def destroyed @destroyed end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
2 3 4 |
# File 'app/services/worker_plugins/remove_collection.rb', line 2 def query @query end |
#workplace ⇒ Object (readonly)
Returns the value of attribute workplace.
2 3 4 |
# File 'app/services/worker_plugins/remove_collection.rb', line 2 def workplace @workplace end |
Instance Method Details
#model_class ⇒ Object
20 21 22 |
# File 'app/services/worker_plugins/remove_collection.rb', line 20 def model_class query.klass end |
#perform ⇒ Object
9 10 11 12 |
# File 'app/services/worker_plugins/remove_collection.rb', line 9 def perform remove_query_from_workplace succeed!(destroyed: destroyed, mode: :destroyed) end |
#query_with_selected_ids ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/services/worker_plugins/remove_collection.rb', line 24 def query_with_selected_ids WorkerPlugins::SelectColumnWithTypeCast.execute!( column_name_to_select: :id, column_to_compare_with: WorkerPlugins::WorkplaceLink.column_for_attribute(:resource_id), query: query ) end |
#remove_query_from_workplace ⇒ Object
14 15 16 17 18 |
# File 'app/services/worker_plugins/remove_collection.rb', line 14 def remove_query_from_workplace links_query = workplace.workplace_links.where(resource_type: model_class.name, resource_id: query_with_selected_ids) @destroyed = links_query.pluck(:resource_id) links_query.delete_all end |