Class: IronAdmin::Field
- Inherits:
-
Object
- Object
- IronAdmin::Field
- Defined in:
- lib/iron_admin/field.rb
Overview
Represents a field configuration for a resource.
Fields are typically inferred from the database schema via FieldInferrer, then customized via the Resource.field DSL. Each Field instance holds the configuration for how a column/attribute should be displayed and edited.
Instance Attribute Summary collapse
-
#name ⇒ Symbol
readonly
The field/column name.
-
#options ⇒ Hash
readonly
Additional field options (e.g., :options, :format, :autocomplete).
-
#readonly ⇒ Boolean, Proc
readonly
Whether the field is read-only.
-
#type ⇒ Symbol
readonly
The field type (:string, :text, :integer, :boolean, :date, :datetime, :select, :belongs_to, etc.).
-
#visible ⇒ Boolean, Proc
readonly
Whether the field is visible.
Instance Method Summary collapse
-
#initialize(name, **options) ⇒ Field
constructor
Creates a new Field instance.
-
#readonly?(user) ⇒ Boolean
Checks if the field is read-only for the given user.
-
#visible?(user) ⇒ Boolean
Checks if the field is visible for the given user.
Constructor Details
#initialize(name, **options) ⇒ Field
Creates a new Field instance.
61 62 63 64 65 66 67 |
# File 'lib/iron_admin/field.rb', line 61 def initialize(name, **) @name = name @type = .delete(:type) @visible = .delete(:visible) { true } @readonly = .delete(:readonly) { false } @options = end |
Instance Attribute Details
#name ⇒ Symbol (readonly)
Returns The field/column name.
24 25 26 |
# File 'lib/iron_admin/field.rb', line 24 def name @name end |
#options ⇒ Hash (readonly)
Returns Additional field options (e.g., :options, :format, :autocomplete).
37 38 39 |
# File 'lib/iron_admin/field.rb', line 37 def @options end |
#readonly ⇒ Boolean, Proc (readonly)
Returns Whether the field is read-only.
34 35 36 |
# File 'lib/iron_admin/field.rb', line 34 def readonly @readonly end |
#type ⇒ Symbol (readonly)
Returns The field type (:string, :text, :integer, :boolean, :date, :datetime, :select, :belongs_to, etc.).
28 29 30 |
# File 'lib/iron_admin/field.rb', line 28 def type @type end |
#visible ⇒ Boolean, Proc (readonly)
Returns Whether the field is visible.
31 32 33 |
# File 'lib/iron_admin/field.rb', line 31 def visible @visible end |
Instance Method Details
#readonly?(user) ⇒ Boolean
Checks if the field is read-only for the given user.
87 88 89 |
# File 'lib/iron_admin/field.rb', line 87 def readonly?(user) evaluate(@readonly, user) end |
#visible?(user) ⇒ Boolean
Checks if the field is visible for the given user.
76 77 78 |
# File 'lib/iron_admin/field.rb', line 76 def visible?(user) evaluate(@visible, user) end |