Class: RailsAdmin::Config::Model
- Inherits:
-
Object
- Object
- RailsAdmin::Config::Model
- 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 =
%i[@parent @root].freeze
Instance Attribute Summary collapse
-
#abstract_model ⇒ Object
readonly
Returns the value of attribute abstract_model.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #excluded? ⇒ Boolean
-
#initialize(entity) ⇒ Model
constructor
A new instance of Model.
-
#method_missing(method_name, *args, &block) ⇒ Object
Act as a proxy for the base section configuration that actually store the configurations.
- #object_label ⇒ Object
- #pluralize(count) ⇒ Object
Methods included from Inspectable
Methods included from Sections
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
Constructor Details
#initialize(entity) ⇒ Model
Returns a new instance of Model.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rails_admin/config/model.rb', line 31 def initialize(entity) @parent = nil @root = self @abstract_model = case entity when RailsAdmin::AbstractModel entity when Class, String RailsAdmin::AbstractModel.new(entity) when Symbol RailsAdmin::AbstractModel.new(entity.to_s) else RailsAdmin::AbstractModel.new(entity.class) 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(method_name, *args, &block) ⇒ Object
Act as a proxy for the base section configuration that actually store the configurations.
115 116 117 |
# File 'lib/rails_admin/config/model.rb', line 115 def method_missing(method_name, *args, &block) send(:base).send(method_name, *args, &block) end |
Instance Attribute Details
#abstract_model ⇒ Object (readonly)
Returns the value of attribute abstract_model.
26 27 28 |
# File 'lib/rails_admin/config/model.rb', line 26 def abstract_model @abstract_model end |
#groups ⇒ Object
Returns the value of attribute groups.
27 28 29 |
# File 'lib/rails_admin/config/model.rb', line 27 def groups @groups end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
26 27 28 |
# File 'lib/rails_admin/config/model.rb', line 26 def parent @parent end |
#root ⇒ Object (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
50 51 52 53 54 |
# File 'lib/rails_admin/config/model.rb', line 50 def excluded? return @excluded if defined?(@excluded) @excluded = !RailsAdmin::AbstractModel.all.collect(&:model_name).include?(abstract_model.try(:model_name)) end |
#object_label ⇒ Object
56 57 58 59 |
# File 'lib/rails_admin/config/model.rb', line 56 def object_label bindings[:object].send(object_label_method).presence || bindings[:object].send(:rails_admin_default_object_label_method) end |
#pluralize(count) ⇒ Object
77 78 79 |
# File 'lib/rails_admin/config/model.rb', line 77 def pluralize(count) count == 1 ? label : label_plural end |