Class: Athar::Deletion
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Athar::Deletion
- Includes:
- ActorLookup
- Defined in:
- lib/athar/deletion.rb
Class Method Summary collapse
- .after(time) ⇒ Object
- .before(time) ⇒ Object
- .for_record(record_or_class, id = nil) ⇒ Object
- .for_record_type(type) ⇒ Object
- .for_table(table_name) ⇒ Object
- .recent ⇒ Object
Methods included from ActorLookup
Class Method Details
.after(time) ⇒ Object
49 50 51 |
# File 'lib/athar/deletion.rb', line 49 def after(time) where(arel_table[:deleted_at].gt(time)) end |
.before(time) ⇒ Object
45 46 47 |
# File 'lib/athar/deletion.rb', line 45 def before(time) where(arel_table[:deleted_at].lt(time)) end |
.for_record(record_or_class, id = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/athar/deletion.rb', line 16 def for_record(record_or_class, id = nil) # Filter by (schema_name, table_name, record_id): # - `record_type` is unreliable because STI subclass rows are stored # under the concrete class name (`"Admin"`) while # `Admin.base_class.name` is `"User"`. # - Active Record returns `"reporting.reporting_buckets"` for models # in non-public schemas, but Athar stores schema and table in # separate columns. Splitting on `.` mirrors what the generator # does at trigger-install time. if id.nil? && record_or_class.is_a?(ActiveRecord::Base) schema, table = split_schema_qualified(record_or_class.class.table_name) where(schema_name: schema, table_name: table, record_id: record_or_class.id) else raise ArgumentError, "id is required when passing a record class or type" if id.nil? klass = record_or_class.is_a?(Class) ? record_or_class : record_or_class.to_s.constantize schema, table = split_schema_qualified(klass.table_name) where(schema_name: schema, table_name: table, record_id: id) end end |
.for_record_type(type) ⇒ Object
37 38 39 |
# File 'lib/athar/deletion.rb', line 37 def for_record_type(type) where(record_type: type.to_s) end |
.for_table(table_name) ⇒ Object
41 42 43 |
# File 'lib/athar/deletion.rb', line 41 def for_table(table_name) where(table_name: table_name.to_s) end |
.recent ⇒ Object
12 13 14 |
# File 'lib/athar/deletion.rb', line 12 def recent order(deleted_at: :desc, id: :desc) end |