Module: InvisibleRecord::Model

Defined in:
lib/invisible_record/model.rb

Overview

Add invisible behavior to an ActiveRecord Model

Instance Method Summary collapse

Instance Method Details

#acts_as_invisible(**options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/invisible_record/model.rb', line 9

def acts_as_invisible(**options)
  options.deep_symbolize_keys!
  deleted_timestamp_attr = options[:deleted_timestamp_attribute] || "deleted_at"
  raise "Only call acts_as_invisible once per model" if respond_to?(:invisible_record_model?)

  include Scopes

  define_default_scopes(deleted_ts_attr: deleted_timestamp_attr)

  class_eval do
    class << self
      def invisible_record_model?
        true
      end
    end

    Helper.define_hidden_attributes self, deleted_ts_attr: deleted_timestamp_attr

    Helper.define_actions self, deleted_ts_attr: deleted_timestamp_attr
  end
end