Class: Workarea::Configuration::Administrable::Fieldset
- Inherits:
-
Object
- Object
- Workarea::Configuration::Administrable::Fieldset
- Defined in:
- lib/workarea/configuration/administrable/fieldset.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #field(name, type: nil, override: false, **options) ⇒ Object
- #find_field(id) ⇒ Object
- #id ⇒ Object
-
#initialize(name, namespaced: true) ⇒ Fieldset
constructor
A new instance of Fieldset.
- #namespaced? ⇒ Boolean
Constructor Details
#initialize(name, namespaced: true) ⇒ Fieldset
Returns a new instance of Fieldset.
7 8 9 10 11 |
# File 'lib/workarea/configuration/administrable/fieldset.rb', line 7 def initialize(name, namespaced: true) @name = name @namespaced = namespaced @fields = SwappableList.new end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
5 6 7 |
# File 'lib/workarea/configuration/administrable/fieldset.rb', line 5 def fields @fields end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/workarea/configuration/administrable/fieldset.rb', line 5 def name @name end |
Instance Method Details
#field(name, type: nil, override: false, **options) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/workarea/configuration/administrable/fieldset.rb', line 21 def field(name, type: nil, override: false, **) field = Field.new(name, fieldset: self, type: type, **) existing = find_field(field.id) if existing.present? && override @fields.swap(existing, field.validate!) elsif existing.present? existing.merge!() existing.validate! else @fields.push(field.validate!) end return unless field.encrypted? Rails.application.config.filter_parameters << field.key end |
#find_field(id) ⇒ Object
38 39 40 |
# File 'lib/workarea/configuration/administrable/fieldset.rb', line 38 def find_field(id) @fields.detect { |field| field.id == id.to_sym } end |
#id ⇒ Object
13 14 15 |
# File 'lib/workarea/configuration/administrable/fieldset.rb', line 13 def id name.to_s.systemize.to_sym end |
#namespaced? ⇒ Boolean
17 18 19 |
# File 'lib/workarea/configuration/administrable/fieldset.rb', line 17 def namespaced? @namespaced end |