Class: RailsAdmin::Config::Model

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

Overview

Model specific configuration object.

Instance Attribute Summary

Attributes inherited from Base

#abstract_model, #bindings, #parent, #root

Instance Method Summary collapse

Methods included from Sections

included

Methods included from Hideable

#hidden?, #hide, included, #show

Methods inherited from Base

#has_option?, register_class_option, #register_deprecated_instance_option, register_deprecated_instance_option, register_instance_option, #register_instance_option, #with

Constructor Details

#initialize(entity) ⇒ Model

Returns a new instance of Model.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rails_admin/config/model.rb', line 12

def initialize(entity)
  @abstract_model = begin
    if entity.kind_of?(RailsAdmin::AbstractModel)
      entity
    elsif entity.kind_of?(Class) || entity.kind_of?(String) || entity.kind_of?(Symbol)
      RailsAdmin::AbstractModel.new(entity)
    else
      RailsAdmin::AbstractModel.new(entity.class)
    end
  end
  @bindings = {}
  @parent = nil
  @root = self
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 section configurations that actually store the configurations.

Raises:

  • (NoMethodError)


76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rails_admin/config/model.rb', line 76

def method_missing(m, *args, &block)
  responded_to = false
  [:create, :list, :show, :navigation, :update, :export].each do |s|
    section = send(s)
    if section.respond_to?(m)
      responded_to = true
      section.send(m, *args, &block)
    end
  end
  raise NoMethodError.new("#{self} has no method #{m}") unless responded_to
end

Instance Method Details

#edit(&block) ⇒ Object

Configure create and update views as a bulk operation with given block or get update view’s configuration if no block is given



33
34
35
36
37
38
# File 'lib/rails_admin/config/model.rb', line 33

def edit(&block)
  return send(:update) unless block_given?
  [:create, :update].each do |s|
    send(s, &block)
  end
end

#excluded?Boolean

Returns:

  • (Boolean)


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

def excluded?
  @excluded ||= !RailsAdmin::AbstractModel.all.map(&:model).include?(abstract_model.model)
end

#object_labelObject



40
41
42
# File 'lib/rails_admin/config/model.rb', line 40

def object_label
  bindings[:object].send object_label_method
end