module Sequel::Plugins::InstanceFilters::InstanceMethods

Public Instance Methods

after_destroy() click to toggle source

Clear the instance filters after successfully destroying the object.

Calls superclass method
# File lib/sequel/plugins/instance_filters.rb, line 51
def after_destroy
  super
  clear_instance_filters
end
after_update() click to toggle source

Clear the instance filters after successfully updating the object.

Calls superclass method
# File lib/sequel/plugins/instance_filters.rb, line 57
def after_update
  super
  clear_instance_filters
end
freeze() click to toggle source

Freeze the instance filters when freezing the object

Calls superclass method
# File lib/sequel/plugins/instance_filters.rb, line 63
def freeze
  instance_filters.freeze
  super
end
instance_filter(*args, &block) click to toggle source

Add an instance filter to the array of instance filters Both the arguments given and the block are passed to the dataset's filter method.

# File lib/sequel/plugins/instance_filters.rb, line 71
def instance_filter(*args, &block)
  instance_filters << [args, block]
end

Private Instance Methods

_delete_dataset() click to toggle source

Apply the instance filters to the dataset returned by super.

Calls superclass method
# File lib/sequel/plugins/instance_filters.rb, line 103
def _delete_dataset
  apply_instance_filters(super)
end
_delete_without_checking() click to toggle source

If there are any instance filters, make sure not to use the instance delete optimization.

Calls superclass method
# File lib/sequel/plugins/instance_filters.rb, line 79
def _delete_without_checking
  if @instance_filters && !@instance_filters.empty?
    _delete_dataset.delete 
  else
    super
  end
end
_update_dataset() click to toggle source

Apply the instance filters to the dataset returned by super.

Calls superclass method
# File lib/sequel/plugins/instance_filters.rb, line 108
def _update_dataset
  apply_instance_filters(super)
end
apply_instance_filters(ds) click to toggle source

Apply the instance filters to the given dataset

# File lib/sequel/plugins/instance_filters.rb, line 93
def apply_instance_filters(ds)
  instance_filters.inject(ds){|ds1, i| ds1.filter(*i[0], &i[1])}
end
clear_instance_filters() click to toggle source

Clear the instance filters.

# File lib/sequel/plugins/instance_filters.rb, line 98
def clear_instance_filters
  instance_filters.clear
end
instance_filters() click to toggle source

Lazily initialize the instance filter array.

# File lib/sequel/plugins/instance_filters.rb, line 88
def instance_filters
  @instance_filters ||= []
end