Sha256: 911db1ae864c8f9da8adff68234e66e43f9f112b8053e05dca77e588eef6e595

Contents?: true

Size: 933 Bytes

Versions: 7

Compression:

Stored size: 933 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, Integer

      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

7 entries across 7 versions & 1 rubygems

Version Path
action_tracker_client-0.1.6 lib/action_tracker/models/application_record.rb
action_tracker_client-0.1.5 lib/action_tracker/models/application_record.rb
action_tracker_client-0.1.4 lib/action_tracker/models/application_record.rb
action_tracker_client-0.1.3 lib/action_tracker/models/application_record.rb
action_tracker_client-0.1.2 lib/action_tracker/models/application_record.rb
action_tracker_client-0.1.1 lib/action_tracker/models/application_record.rb
action_tracker_client-0.1.0 lib/action_tracker/models/application_record.rb