Sha256: 8bd66a902853f571021e25be721d29fc3bb7254f5f2eea6f22140ca91f4da310

Contents?: true

Size: 786 Bytes

Versions: 1

Compression:

Stored size: 786 Bytes

Contents

# frozen_string_literal: true

module Simpleadmin
  module Decorators
    module Fields
      class Base
        def initialize(table_name, table_field_name, resource)
          @table_name = table_name
          @table_field_name = table_field_name

          @resource = resource
        end

        def call
          raise NotImplementedError, 'Please follow the unified interface, add method #call'
        end

        private

        attr_reader :table_name, :table_field_name, :resource

        def model
          model_class = table_name.classify.safe_constantize

          if model_class.nil?
            raise ArgumentError, "The model (#{table_name.classify}) does not exist"
          else
            model_class
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simpleadmin-1.5.0 lib/simpleadmin/decorators/fields/base.rb