Class: CrudComponents::Fieldset
- Inherits:
-
Object
- Object
- CrudComponents::Fieldset
- Defined in:
- lib/crud_components/fieldset.rb
Overview
A named selection of fields and actions. ‘filters:` extends the filterable set beyond the visible fields (“filter only what you can see” is the default rule).
Instance Attribute Summary collapse
-
#action_spec ⇒ Object
readonly
Returns the value of attribute action_spec.
-
#field_names ⇒ Object
readonly
Returns the value of attribute field_names.
-
#filter_names ⇒ Object
readonly
Returns the value of attribute filter_names.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#action_names ⇒ Array<Symbol>?
The curated action names (‘actions: %i[edit destroy]`), or nil when the derived defaults apply.
-
#all_fields? ⇒ Boolean
Whether this fieldset shows every field.
-
#custom_actions_partial ⇒ String?
A custom actions partial (‘actions: ’books/actions’‘, receiving `record`), or nil.
-
#initialize(name, fields = :all, actions: nil, filters: nil) ⇒ Fieldset
constructor
A new instance of Fieldset.
Constructor Details
#initialize(name, fields = :all, actions: nil, filters: nil) ⇒ Fieldset
Returns a new instance of Fieldset.
14 15 16 17 18 19 |
# File 'lib/crud_components/fieldset.rb', line 14 def initialize(name, fields = :all, actions: nil, filters: nil) @name = name.to_sym @field_names = fields == :all ? :all : Array(fields).map(&:to_sym) @action_spec = actions @filter_names = Array(filters || []).map(&:to_sym) end |
Instance Attribute Details
#action_spec ⇒ Object (readonly)
Returns the value of attribute action_spec.
6 7 8 |
# File 'lib/crud_components/fieldset.rb', line 6 def action_spec @action_spec end |
#field_names ⇒ Object (readonly)
Returns the value of attribute field_names.
6 7 8 |
# File 'lib/crud_components/fieldset.rb', line 6 def field_names @field_names end |
#filter_names ⇒ Object (readonly)
Returns the value of attribute filter_names.
6 7 8 |
# File 'lib/crud_components/fieldset.rb', line 6 def filter_names @filter_names end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/crud_components/fieldset.rb', line 6 def name @name end |
Instance Method Details
#action_names ⇒ Array<Symbol>?
The curated action names (‘actions: %i[edit destroy]`), or nil when the derived defaults apply.
27 28 29 |
# File 'lib/crud_components/fieldset.rb', line 27 def action_names @action_spec.is_a?(Array) ? @action_spec.map(&:to_sym) : nil end |
#all_fields? ⇒ Boolean
Returns whether this fieldset shows every field.
22 |
# File 'lib/crud_components/fieldset.rb', line 22 def all_fields? = @field_names == :all |
#custom_actions_partial ⇒ String?
A custom actions partial (‘actions: ’books/actions’‘, receiving `record`), or nil.
34 35 36 |
# File 'lib/crud_components/fieldset.rb', line 34 def custom_actions_partial @action_spec.is_a?(String) ? @action_spec : nil end |