Sha256: 8f5efccd1fd8d9bb18e4d883cdd6d222e9adffdce1ad70977209e7001a1b90c3

Contents?: true

Size: 1.05 KB

Versions: 13

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module RailsAdmin
  module Config
    module Inspectable
      def inspect
        set_named_instance_variables

        instance_name = try(:name) || try(:abstract_model).try(:model).try(:name)
        instance_name = instance_name ? "[#{instance_name}]" : ''

        instance_vars = instance_variables.collect do |v|
          instance_variable_name(v)
        end.join(', ')

        "#<#{self.class.name}#{instance_name} #{instance_vars}>"
      end

    private

      def instance_variable_name(variable)
        value = instance_variable_get(variable)
        if self.class::NAMED_INSTANCE_VARIABLES.include?(variable)
          if value.respond_to?(:name)
            "#{variable}=#{value.name.inspect}"
          else
            "#{variable}=#{value.class.name}"
          end
        else
          "#{variable}=#{value.inspect}"
        end
      end

      def set_named_instance_variables
        self.class.const_set('NAMED_INSTANCE_VARIABLES', []) unless defined?(self.class::NAMED_INSTANCE_VARIABLES)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rails_admin-3.3.0 lib/rails_admin/config/inspectable.rb
rails_admin-3.2.1 lib/rails_admin/config/inspectable.rb
rails_admin-3.2.0 lib/rails_admin/config/inspectable.rb
rails_admin-3.2.0.rc lib/rails_admin/config/inspectable.rb
rails_admin-3.2.0.beta lib/rails_admin/config/inspectable.rb
rails_admin-3.1.4 lib/rails_admin/config/inspectable.rb
rails_admin-3.1.3 lib/rails_admin/config/inspectable.rb
rails_admin-3.1.2 lib/rails_admin/config/inspectable.rb
rails_admin-3.1.1 lib/rails_admin/config/inspectable.rb
rails_admin-3.1.0 lib/rails_admin/config/inspectable.rb
rails_admin-3.1.0.rc2 lib/rails_admin/config/inspectable.rb
rails_admin-3.1.0.rc lib/rails_admin/config/inspectable.rb
rails_admin-3.1.0.beta lib/rails_admin/config/inspectable.rb