Class: RailsAdmin::Config::Fields::Base
- Includes:
- Hideable
- Defined in:
- lib/rails_admin/config/fields/base.rb
Direct Known Subclasses
Association, Types::Boolean, Types::Color, Types::Datetime, Types::Decimal, Types::Enum, Types::FileUpload, Types::Float, Types::Integer, Types::String, Types::Text
Instance Attribute Summary collapse
-
#defined ⇒ Object
Returns the value of attribute defined.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#order ⇒ Object
Returns the value of attribute order.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Attributes inherited from Base
#abstract_model, #bindings, #parent, #root
Class Method Summary collapse
Instance Method Summary collapse
-
#association? ⇒ Boolean
Is this an association.
- #column_css_class(*args, &block) ⇒ Object
-
#dom_id ⇒ Object
Reader for field’s id.
-
#dom_name ⇒ Object
Reader for field’s name.
-
#errors ⇒ Object
Reader for validation errors of the bound object.
-
#has_errors? ⇒ Boolean
Reader whether the bound object has validation errors.
-
#initialize(parent, name, properties) ⇒ Base
constructor
A new instance of Base.
- #method_name ⇒ Object
-
#optional(state = nil, &block) ⇒ Object
Inverse accessor whether this field is required.
-
#optional=(state) ⇒ Object
Writer to make field optional.
-
#optional? ⇒ Boolean
Reader whether field is optional.
-
#type ⇒ Object
Reader for field’s type.
-
#value ⇒ Object
Reader for field’s value.
- #virtual? ⇒ Boolean
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(parent, name, properties) ⇒ Base
Returns a new instance of Base.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rails_admin/config/fields/base.rb', line 23 def initialize(parent, name, properties) super(parent) @defined = false @name = name @order = 0 @properties = properties # If parent is able to group fields the field should be aware of it if parent.kind_of?(RailsAdmin::Config::HasGroups) extend RailsAdmin::Config::Fields::Groupable end end |
Instance Attribute Details
#defined ⇒ Object
Returns the value of attribute defined.
14 15 16 |
# File 'lib/rails_admin/config/fields/base.rb', line 14 def defined @defined end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/rails_admin/config/fields/base.rb', line 13 def name @name end |
#order ⇒ Object
Returns the value of attribute order.
14 15 16 |
# File 'lib/rails_admin/config/fields/base.rb', line 14 def order @order end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
13 14 15 |
# File 'lib/rails_admin/config/fields/base.rb', line 13 def properties @properties end |
Class Method Details
.inherited(klass) ⇒ Object
16 17 18 19 |
# File 'lib/rails_admin/config/fields/base.rb', line 16 def self.inherited(klass) klass.instance_variable_set("@css_class", klass.name.to_s.demodulize.camelcase(:lower)) klass.instance_variable_set("@view_helper", :text_field) end |
Instance Method Details
#association? ⇒ Boolean
Is this an association
203 204 205 |
# File 'lib/rails_admin/config/fields/base.rb', line 203 def association? kind_of?(RailsAdmin::Config::Fields::Association) end |
#column_css_class(*args, &block) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/rails_admin/config/fields/base.rb', line 41 def column_css_class(*args, &block) if !args[0].nil? || block @css_class = args[0].nil? ? block : args[0] else css_class end end |
#dom_id ⇒ Object
Reader for field’s id
259 260 261 262 263 264 265 |
# File 'lib/rails_admin/config/fields/base.rb', line 259 def dom_id @dom_id ||= [ bindings[:form].object_name, bindings[:form].[:index], method_name ].reject(&:blank?).join('_') end |
#dom_name ⇒ Object
Reader for field’s name
254 255 256 |
# File 'lib/rails_admin/config/fields/base.rb', line 254 def dom_name @dom_name ||= "#{bindings[:form].object_name}#{(index = bindings[:form].[:index]) && "[#{index}]"}[#{method_name}]" end |
#errors ⇒ Object
Reader for validation errors of the bound object
208 209 210 |
# File 'lib/rails_admin/config/fields/base.rb', line 208 def errors bindings[:object].errors[name] end |
#has_errors? ⇒ Boolean
Reader whether the bound object has validation errors
213 214 215 216 |
# File 'lib/rails_admin/config/fields/base.rb', line 213 def has_errors? # TODO DEPRECATE, USELESS errors.present? end |
#method_name ⇒ Object
267 268 269 |
# File 'lib/rails_admin/config/fields/base.rb', line 267 def method_name name end |
#optional(state = nil, &block) ⇒ Object
Inverse accessor whether this field is required.
228 229 230 231 232 233 234 |
# File 'lib/rails_admin/config/fields/base.rb', line 228 def optional(state = nil, &block) if !state.nil? || block required state.nil? ? proc { false == (instance_eval &block) } : false == state else optional? end end |
#optional=(state) ⇒ Object
Writer to make field optional.
239 240 241 |
# File 'lib/rails_admin/config/fields/base.rb', line 239 def optional=(state) optional(state) end |
#optional? ⇒ Boolean
Reader whether field is optional.
221 222 223 |
# File 'lib/rails_admin/config/fields/base.rb', line 221 def optional? not required end |
#type ⇒ Object
Reader for field’s type
244 245 246 |
# File 'lib/rails_admin/config/fields/base.rb', line 244 def type @type ||= self.class.name.to_s.demodulize.underscore.to_sym end |
#value ⇒ Object
Reader for field’s value
249 250 251 |
# File 'lib/rails_admin/config/fields/base.rb', line 249 def value bindings[:object].safe_send(name) end |
#virtual? ⇒ Boolean
49 50 51 |
# File 'lib/rails_admin/config/fields/base.rb', line 49 def virtual? properties.blank? end |