Class: Workarea::Configuration::Administrable::Definition
- Inherits:
-
Object
- Object
- Workarea::Configuration::Administrable::Definition
- Defined in:
- lib/workarea/configuration/administrable/definition.rb
Instance Attribute Summary collapse
-
#fieldsets ⇒ Object
readonly
Returns the value of attribute fieldsets.
Instance Method Summary collapse
- #application_fieldset ⇒ Object
- #fields ⇒ Object
- #fieldset(name, override: false, namespaced: true, &block) ⇒ Object
- #find_fieldset(id) ⇒ Object
-
#initialize ⇒ Definition
constructor
A new instance of Definition.
Constructor Details
#initialize ⇒ Definition
Returns a new instance of Definition.
8 9 10 11 |
# File 'lib/workarea/configuration/administrable/definition.rb', line 8 def initialize @fieldsets = SwappableList.new @fieldsets.push(Fieldset.new('Application', namespaced: false)) end |
Instance Attribute Details
#fieldsets ⇒ Object (readonly)
Returns the value of attribute fieldsets.
5 6 7 |
# File 'lib/workarea/configuration/administrable/definition.rb', line 5 def fieldsets @fieldsets end |
Instance Method Details
#application_fieldset ⇒ Object
28 29 30 |
# File 'lib/workarea/configuration/administrable/definition.rb', line 28 def application_fieldset @application_fieldset ||= find_fieldset(:application) end |
#fields ⇒ Object
36 37 38 |
# File 'lib/workarea/configuration/administrable/definition.rb', line 36 def fields @fieldsets.flat_map(&:fields) end |
#fieldset(name, override: false, namespaced: true, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/workarea/configuration/administrable/definition.rb', line 13 def fieldset(name, override: false, namespaced: true, &block) fieldset = Fieldset.new(name, namespaced: namespaced) existing = find_fieldset(fieldset.id) if override && existing.present? @fieldsets.swap(existing, fieldset) fieldset.instance_eval(&block) if block_given? elsif existing.present? existing.instance_eval(&block) if block_given? else @fieldsets.push(fieldset) fieldset.instance_eval(&block) if block_given? end end |
#find_fieldset(id) ⇒ Object
32 33 34 |
# File 'lib/workarea/configuration/administrable/definition.rb', line 32 def find_fieldset(id) @fieldsets.detect { |fieldset| fieldset.id == id.to_sym } end |