mirror of
https://github.com/neocities/neocities.git
synced 2025-08-02 15:51:55 +02:00
refactor site_updated, add initial site file tracking
This commit is contained in:
parent
f50b3a23d9
commit
05807e2f39
7 changed files with 44 additions and 10 deletions
8
ext/sequel/plugins/create_timestamp.rb
Normal file
8
ext/sequel/plugins/create_timestamp.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
module Sequel::Plugins::CreateTimestamp
|
||||
module InstanceMethods
|
||||
def before_create
|
||||
self.created_at = Time.now if respond_to?(:created_at) && !self.created_at
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
32
ext/sequel/plugins/paranoid_delete.rb
Normal file
32
ext/sequel/plugins/paranoid_delete.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Sequel
|
||||
module ParanoidDelete
|
||||
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
||||
end
|
||||
|
||||
# Instead of actually deleting, we just set is_deleted to true,
|
||||
# and look for it with our default dataset filter.
|
||||
def delete
|
||||
self.is_deleted = true
|
||||
save :validate => false
|
||||
true
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
# There's no hook for setting default filters after inheritance (that I'm aware of),
|
||||
# so this adds the filter for the first time the class' dataset is accessed for the new model.
|
||||
def dataset
|
||||
if @_is_deleted_filter_set.nil?
|
||||
@dataset.filter! is_deleted: false
|
||||
@_is_deleted_filter_set = true
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# Model.include ParanoidDelete
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue