Module: Millstone::ActiveRecord::Extension::ClassMethods

Defined in:
lib/millstone/active_record/extension.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Instance Method Summary collapse

Instance Method Details

#as_millstone?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/millstone/active_record/extension.rb', line 21

def as_millstone?
  self.included_modules.include?(InstanceMethods)
end

#millstone(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/millstone/active_record/extension.rb', line 25

def millstone(options = {})
  options = options.reverse_merge(:column => :deleted_at, :type => :time)

  unless [:time, :boolean].include? options[:type]
    raise ArgumentError, "'time' or 'boolean' expected for :type option, got #{options[:type]}"
  end

  class_attribute :millstone_configuration, :millstone_column_reference
  self.millstone_configuration = options
  self.millstone_column_reference = "#{self.table_name}.#{millstone_configuration[:column]}"
  
  return if as_millstone?

  extend ClassMethods
  include InstanceMethods
  include Validations

  self.class_eval do
    alias_method :paranoid_value, :millstone_column_value
  end

  class << self
    delegate :destroy!, :destroy_all!, :delete!, :delete_all!, :to => :scoped
    delegate :with_deleted, :only_deleted, :to => :scoped
    alias_method_chain :relation, :millstone

    # for acts_as_paranoid
    alias_method :paranoid_column, :millstone_column
    alias_method :paranoid_column_type, :millstone_type
    alias_method :paranoid_column_reference, :millstone_column_reference
    alias_method :paranoid_configuration, :millstone_configuration
  end
end