Class: RailsAdmin::Config::Fields::Base
- Inherits:
-
Object
- Object
- RailsAdmin::Config::Fields::Base
- Includes:
- Configurable, Groupable, Hideable, Proxyable
- 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::Hidden, Types::Integer, Types::String, Types::Text
Instance Attribute Summary (collapse)
-
- (Object) abstract_model
readonly
Returns the value of attribute abstract_model.
-
- (Object) defined
Returns the value of attribute defined.
-
- (Object) name
readonly
Returns the value of attribute name.
-
- (Object) order
Returns the value of attribute order.
-
- (Object) parent
readonly
Returns the value of attribute parent.
-
- (Object) properties
readonly
Returns the value of attribute properties.
-
- (Object) root
readonly
Returns the value of attribute root.
-
- (Object) section
Returns the value of attribute section.
Attributes included from Proxyable
Instance Method Summary (collapse)
-
- (Boolean) association?
Is this an association.
- - (Boolean) editable?
-
- (Object) errors
Reader for validation errors of the bound object.
- - (Object) html_default_value
-
- (Base) initialize(parent, name, properties)
constructor
A new instance of Base.
- - (Object) inspect
- - (Object) inverse_of
- - (Object) method_name
-
- (Object) optional(state = nil, &block)
Inverse accessor whether this field is required.
-
- (Object) optional=(state)
Writer to make field optional.
-
- (Boolean) optional?
Reader whether field is optional.
-
- (Object) type
Reader for field's type.
- - (Object) type_css_class
-
- (Object) value
Reader for field's value.
- - (Boolean) virtual?
Methods included from Groupable
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
Constructor Details
- (Base) initialize(parent, name, properties)
A new instance of Base
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rails_admin/config/fields/base.rb', line 19 def initialize(parent, name, properties) @parent = parent @root = parent.root @abstract_model = parent.abstract_model @defined = false @name = name.to_sym @order = 0 @properties = properties @section = parent end |
Instance Attribute Details
- (Object) abstract_model (readonly)
Returns the value of attribute abstract_model
15 16 17 |
# File 'lib/rails_admin/config/fields/base.rb', line 15 def abstract_model @abstract_model end |
- (Object) defined
Returns the value of attribute defined
16 17 18 |
# File 'lib/rails_admin/config/fields/base.rb', line 16 def defined @defined end |
- (Object) name (readonly)
Returns the value of attribute name
15 16 17 |
# File 'lib/rails_admin/config/fields/base.rb', line 15 def name @name end |
- (Object) order
Returns the value of attribute order
16 17 18 |
# File 'lib/rails_admin/config/fields/base.rb', line 16 def order @order end |
- (Object) parent (readonly)
Returns the value of attribute parent
17 18 19 |
# File 'lib/rails_admin/config/fields/base.rb', line 17 def parent @parent end |
- (Object) properties (readonly)
Returns the value of attribute properties
15 16 17 |
# File 'lib/rails_admin/config/fields/base.rb', line 15 def properties @properties end |
- (Object) root (readonly)
Returns the value of attribute root
17 18 19 |
# File 'lib/rails_admin/config/fields/base.rb', line 17 def root @root end |
- (Object) section
Returns the value of attribute section
16 17 18 |
# File 'lib/rails_admin/config/fields/base.rb', line 16 def section @section end |
Instance Method Details
- (Boolean) association?
Is this an association
216 217 218 |
# File 'lib/rails_admin/config/fields/base.rb', line 216 def association? kind_of?(RailsAdmin::Config::Fields::Association) end |
- (Boolean) editable?
210 211 212 213 |
# File 'lib/rails_admin/config/fields/base.rb', line 210 def editable? return false if @properties && @properties[:read_only] !bindings[:object].class.[bindings[:view].controller.send(:_attr_accessible_role)].deny?(self.method_name) end |
- (Object) errors
Reader for validation errors of the bound object
221 222 223 224 225 |
# File 'lib/rails_admin/config/fields/base.rb', line 221 def errors ([name] + children_fields).uniq.map do |column_name| bindings[:object].errors[column_name] end.uniq.flatten end |
- (Object) html_default_value
275 276 277 |
# File 'lib/rails_admin/config/fields/base.rb', line 275 def html_default_value bindings[:object].new_record? && self.value.nil? && !self.default_value.nil? ? self.default_value : nil end |
- (Object) inspect
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/rails_admin/config/fields/base.rb', line 279 def inspect "#<#{self.class.name}[#{name}] #{ instance_variables.map do |v| value = instance_variable_get(v) if [:@parent, :@root, :@section, :@children_fields_registered, :@associated_model_config, :@group, :@bindings].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) inverse_of
267 268 269 |
# File 'lib/rails_admin/config/fields/base.rb', line 267 def inverse_of nil end |
- (Object) method_name
271 272 273 |
# File 'lib/rails_admin/config/fields/base.rb', line 271 def method_name name end |
- (Object) optional(state = nil, &block)
Inverse accessor whether this field is required.
237 238 239 240 241 242 243 |
# File 'lib/rails_admin/config/fields/base.rb', line 237 def optional(state = nil, &block) if !state.nil? || block required state.nil? ? proc { false == (instance_eval &block) } : false == state else optional? end end |
- (Object) optional=(state)
Writer to make field optional.
248 249 250 |
# File 'lib/rails_admin/config/fields/base.rb', line 248 def optional=(state) optional(state) end |
- (Boolean) optional?
Reader whether field is optional.
230 231 232 |
# File 'lib/rails_admin/config/fields/base.rb', line 230 def optional? not required? end |
- (Object) type
Reader for field's type
253 254 255 |
# File 'lib/rails_admin/config/fields/base.rb', line 253 def type @type ||= self.class.name.to_s.demodulize.underscore.to_sym end |
- (Object) type_css_class
35 36 37 |
# File 'lib/rails_admin/config/fields/base.rb', line 35 def type_css_class "#{type}_type" end |
- (Object) value
Reader for field's value
258 259 260 |
# File 'lib/rails_admin/config/fields/base.rb', line 258 def value bindings[:object].safe_send(name) end |
- (Boolean) virtual?
39 40 41 |
# File 'lib/rails_admin/config/fields/base.rb', line 39 def virtual? properties.blank? end |