module ActAsDisabled::Query
Public Class Methods
extended(base)
click to toggle source
# File lib/act_as_disabled.rb, line 9 def self.extended(base) base.define_callbacks :disable end
Public Instance Methods
aad_column()
click to toggle source
# File lib/act_as_disabled.rb, line 57 def aad_column aad_config[:column].to_sym end
aad_column_reference()
click to toggle source
# File lib/act_as_disabled.rb, line 64 def aad_column_reference "#{table_name}.#{aad_column}" end
aad_column_type()
click to toggle source
# File lib/act_as_disabled.rb, line 60 def aad_column_type aad_config[:column_type].to_sym end
aad_default_scope()
click to toggle source
# File lib/act_as_disabled.rb, line 12 def aad_default_scope scope = all if string_type_with_deleted_value? scope.where(aad_column => nil).or(scope.where.not(aad_column => aad_config[:deleted_value])) elsif boolean_type_not_nullable? scope.where(aad_column => false) else scope.where(aad_column => nil) end end
boolean_type_not_nullable?()
click to toggle source
# File lib/act_as_disabled.rb, line 53 def boolean_type_not_nullable? aad_column_type == 'boolean'.to_sym && !aad_config[:allow_nulls] end
delete_now_value()
click to toggle source
# File lib/act_as_disabled.rb, line 68 def delete_now_value case aad_config[:column_type] when "time" then Time.now when "boolean" then true when "string" then aad_config[:deleted_value] else raise ArgumentError, "'time', 'boolean' or 'string' expected" \ " for :column_type option, got #{aad_config[:column_type]}" end end
only_disabled()
click to toggle source
# File lib/act_as_disabled.rb, line 38 def only_disabled if string_type_with_deleted_value? without_aad_default_scope .where(aad_column => aad_config[:deleted_value]) elsif boolean_type_not_nullable? without_aad_default_scope.where(aad_column => true) else without_aad_default_scope.where.not(aad_column => nil) end end
string_type_with_deleted_value?()
click to toggle source
# File lib/act_as_disabled.rb, line 49 def string_type_with_deleted_value? aad_column_type == 'string'.to_sym && !aad_config[:deleted_value].nil? end
with_disabled()
click to toggle source
remove remove every thing from the query select * from models
# File lib/act_as_disabled.rb, line 34 def with_disabled without_aad_default_scope end
without_aad_default_scope()
click to toggle source
# File lib/act_as_disabled.rb, line 23 def without_aad_default_scope scope = all scope = scope.unscope(where: aad_column) # Fix problems with unscope group chain scope = scope.unscoped if scope.to_sql.include? aad_default_scope.to_sql scope end