Class: RailsAdmin::Config::Model

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

Overview

Model specific configuration object.

Instance Attribute Summary (collapse)

Attributes included from Proxyable

#bindings

Instance Method Summary (collapse)

Methods included from Hideable

#hidden?, #hide, included, #show

Methods included from Configurable

#has_option?, #register_deprecated_instance_option, #register_instance_option

Methods included from Proxyable

#with

Constructor Details

- (Model) initialize(entity)



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rails_admin/config/model.rb', line 26

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

  @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
  @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

- (Object) method_missing(m, *args, &block)

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



83
84
85
# File 'lib/rails_admin/config/model.rb', line 83

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

Instance Attribute Details

- (Object) abstract_model (readonly)

Returns the value of attribute abstract_model



22
23
24
# File 'lib/rails_admin/config/model.rb', line 22

def abstract_model
  @abstract_model
end

- (Object) groups

Returns the value of attribute groups



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

def groups
  @groups
end

- (Object) parent (readonly)

Returns the value of attribute parent



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

def parent
  @parent
end

- (Object) root (readonly)

Returns the value of attribute root



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

def root
  @root
end

Instance Method Details

- (Boolean) excluded?



42
43
44
# File 'lib/rails_admin/config/model.rb', line 42

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

- (Object) inspect



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rails_admin/config/model.rb', line 87

def inspect
  "#<#{self.class.name}[#{abstract_model.model.name}] #{
    instance_variables.map do |v|
      value = instance_variable_get(v)
      if [:@parent, :@root].include? v
        if value.respond_to? :name
          "#{v}=#{value.name.inspect}"
        else
          "#{v}=#{value.class.name}"
        end
      else
        "#{v}=#{value.inspect}"
      end
    end.join(", ")
  }>"
end

- (Object) object_label



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

def object_label
  bindings[:object].send object_label_method
end