Sha256: d58cb4d024f8bb2439a80a09bf37cab8cbaca05f5f8580909c5a428f4abacff1

Contents?: true

Size: 853 Bytes

Versions: 2

Compression:

Stored size: 853 Bytes

Contents

# frozen_string_literal: true

require "invisible_record/helper"
require "invisible_record/scopes"

module InvisibleRecord
  # Add invisible behavior to an ActiveRecord Model
  module Model
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
invisible_record-0.2.1 lib/invisible_record/model.rb
invisible_record-0.2.0 lib/invisible_record/model.rb