Sha256: 5cc6292e5f8cc03d98d499ada216bd38f6f37c279540c9a323611826e1aba6f6

Contents?: true

Size: 1.18 KB

Versions: 28

Compression:

Stored size: 1.18 KB

Contents

module Workarea
  module Configuration
    module Administrable
      class Definition
        attr_reader :fieldsets
        delegate :field, to: :application_fieldset

        def initialize
          @fieldsets = SwappableList.new
          @fieldsets.push(Fieldset.new('Application', namespaced: false))
        end

        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

        def application_fieldset
          @application_fieldset ||= find_fieldset(:application)
        end

        def find_fieldset(id)
          @fieldsets.detect { |fieldset| fieldset.id == id.to_sym }
        end

        def fields
          @fieldsets.flat_map(&:fields)
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-core-3.5.27 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.26 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.25 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.23 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.22 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.21 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.20 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.19 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.18 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.17 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.16 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.15 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.14 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.13 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.12 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.11 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.10 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.9 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.8 lib/workarea/configuration/administrable/definition.rb
workarea-core-3.5.7 lib/workarea/configuration/administrable/definition.rb