Class: SolidObjects::Instance
- Inherits:
-
Record
- Object
- ActiveRecord::Base
- Record
- SolidObjects::Instance
- Defined in:
- app/models/solid_objects/instance.rb,
sig/generated/models/solid_objects/instance.rbs
Class Method Summary collapse
- .active(actor_type: nil) ⇒ ActiveRecord::Relation[Instance]
- .orphaned(actor_type:, owner:) ⇒ ActiveRecord::Relation[Instance]
- .states_for(actor_type:, actor_ids:) ⇒ Hash[String, Hash[String, untyped]]
- .without_pending_work(quiet_for:, now: SolidObjects.database_adapter.database_now) ⇒ ActiveRecord::Relation[Instance]
Instance Method Summary collapse
Methods inherited from Record
Class Method Details
.active(actor_type: nil) ⇒ ActiveRecord::Relation[Instance]
30 31 32 33 |
# File 'app/models/solid_objects/instance.rb', line 30 def active(actor_type: nil) relation = where(paused_at: nil) actor_type ? relation.where(actor_type:) : relation end |
.orphaned(actor_type:, owner:) ⇒ ActiveRecord::Relation[Instance]
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/solid_objects/instance.rb', line 47 def orphaned(actor_type:, owner:) owner_relation = owner.is_a?(ActiveRecord::Relation) ? owner : owner.all owner_class = owner_relation.klass owner_table = owner_class.arel_table owner_primary_key = owner_table[owner_class.primary_key] cast_type = Arel::Nodes::SqlLiteral.new(owner_id_cast_type) cast_id = Arel::Nodes::NamedFunction.new( "CAST", [ Arel::Nodes::As.new(owner_primary_key, cast_type) ] ) owner_ids = owner_relation .except(:select) .select(cast_id) where(actor_type:).where.not(actor_id: owner_ids) end |
.states_for(actor_type:, actor_ids:) ⇒ Hash[String, Hash[String, untyped]]
65 66 67 68 69 |
# File 'app/models/solid_objects/instance.rb', line 65 def states_for(actor_type:, actor_ids:) where(actor_type:, actor_id: actor_ids) .pluck(:actor_id, :state) .to_h end |
.without_pending_work(quiet_for:, now: SolidObjects.database_adapter.database_now) ⇒ ActiveRecord::Relation[Instance]
36 37 38 39 40 41 42 43 44 |
# File 'app/models/solid_objects/instance.rb', line 36 def without_pending_work(quiet_for:, now: SolidObjects.database_adapter.database_now) cutoff = now - quiet_for where("COALESCE(last_used_at, created_at) <= ?", cutoff) .where.not(id: ReadyMessage.select(:instance_id)) .where.not(id: ClaimedMessage.select(:instance_id)) .where.not( id: Reminder.where(status: "scheduled").select(:instance_id) ) end |
Instance Method Details
#supply_defaults ⇒ void
This method returns an undefined value.
89 90 91 |
# File 'app/models/solid_objects/instance.rb', line 89 def supply_defaults self.state ||= {} end |