Sha256: 3cd3891db1223d099be2f6c472c5edc1f99e7ce2b4d2cb1b4f70d093ac19a1f7

Contents?: true

Size: 932 Bytes

Versions: 2

Compression:

Stored size: 932 Bytes

Contents

# frozen_string_literal: true

require 'virtus'
require 'active_model'

module ActionTracker
  module Models
    class ApplicationRecord
      include Virtus.model
      include ActiveModel::Validations

      attribute :id, String

      def self.mimic(model_name)
        @model_name = model_name.to_s.underscore.to_sym
      end

      def self.mimicked_model_name
        @model_name || infer_model_name
      end

      def self.infer_model_name
        class_name = name.split('::').last
        return :form if class_name == 'Form'

        class_name.chomp('Form').underscore.to_sym
      end

      def self.model_name
        ActiveModel::Name.new(self, nil, mimicked_model_name.to_s.camelize)
      end

      def model_name
        self.class.model_name
      end

      def to_key
        [id]
      end

      def present_attributes
        attributes.reject { |_key, value| value.blank? }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
action_tracker_client-0.1.8 lib/action_tracker/models/application_record.rb
action_tracker_client-0.1.7 lib/action_tracker/models/application_record.rb