Class: RailsAdmin::Config::Model

Inherits:
Object
  • Object
show all
Includes:
Configurable, Hideable, Inspectable, Proxyable, Sections
Defined in:
lib/rails_admin/config/model.rb

Overview

Model specific configuration object.

Constant Summary collapse

NAMED_INSTANCE_VARIABLES =
[:@parent, :@root].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inspectable

#inspect

Methods included from Sections

included

Methods included from Hideable

#hidden?, #hide, included, #show

Methods included from Configurable

#has_option?, included, #register_deprecated_instance_option, #register_instance_option

Methods included from Proxyable

#bindings, #bindings=, #with

Constructor Details

#initialize(entity) ⇒ Model

Returns a new instance of Model.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rails_admin/config/model.rb', line 30

def initialize(entity)
  @parent = nil
  @root = self

  @abstract_model = begin
    if entity.is_a?(RailsAdmin::AbstractModel)
      entity
    elsif entity.is_a?(Class) || entity.is_a?(String) || entity.is_a?(Symbol)
      RailsAdmin::AbstractModel.new(entity)
    else
      RailsAdmin::AbstractModel.new(entity.class)
    end
  end
  @groups = [RailsAdmin::Config::Fields::Group.new(self, :default).tap { |g| g.label { I18n.translate('admin.form.basic_info') } }]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object

Act as a proxy for the base section configuration that actually store the configurations.



103
104
105
# File 'lib/rails_admin/config/model.rb', line 103

def method_missing(m, *args, &block)
  send(:base).send(m, *args, &block)
end

Instance Attribute Details

#abstract_modelObject (readonly)

Returns the value of attribute abstract_model.



24
25
26
# File 'lib/rails_admin/config/model.rb', line 24

def abstract_model
  @abstract_model
end

#groupsObject

Returns the value of attribute groups.



25
26
27
# File 'lib/rails_admin/config/model.rb', line 25

def groups
  @groups
end

#parentObject (readonly)

Returns the value of attribute parent.



26
27
28
# File 'lib/rails_admin/config/model.rb', line 26

def parent
  @parent
end

#rootObject (readonly)

Returns the value of attribute root.



26
27
28
# File 'lib/rails_admin/config/model.rb', line 26

def root
  @root
end

Instance Method Details

#excluded?Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/rails_admin/config/model.rb', line 46

def excluded?
  return @excluded if defined?(@excluded)
  @excluded = !RailsAdmin::AbstractModel.all.collect(&:model_name).include?(abstract_model.try(:model_name))
end

#object_labelObject



51
52
53
54
# File 'lib/rails_admin/config/model.rb', line 51

def object_label
  bindings[:object].send(object_label_method).presence ||
    bindings[:object].send(:rails_admin_default_object_label_method)
end

#pluralize(count) ⇒ Object



72
73
74
# File 'lib/rails_admin/config/model.rb', line 72

def pluralize(count)
  count == 1 ? label : label_plural
end