Sha256: fed4246f995fb832021161c9796a456819805d203d8a9167f0be38ecb04ef0da

Contents?: true

Size: 1.07 KB

Versions: 28

Compression:

Stored size: 1.07 KB

Contents

module Workarea
  module Configuration
    module Administrable
      class Fieldset
        attr_accessor :fields, :name

        def initialize(name, namespaced: true)
          @name = name
          @namespaced = namespaced
          @fields = SwappableList.new
        end

        def id
          name.to_s.systemize.to_sym
        end

        def namespaced?
          @namespaced
        end

        def field(name, type: nil, override: false, **options)
          field = Field.new(name, fieldset: self, type: type, **options)
          existing = find_field(field.id)

          if existing.present? && override
            @fields.swap(existing, field.validate!)
          elsif existing.present?
            existing.merge!(options)
            existing.validate!
          else
            @fields.push(field.validate!)
          end

          return unless field.encrypted?
          Rails.application.config.filter_parameters << field.key
        end

        def find_field(id)
          @fields.detect { |field| field.id == id.to_sym }
        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/fieldset.rb
workarea-core-3.5.26 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.25 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.23 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.22 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.21 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.20 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.19 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.18 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.17 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.16 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.15 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.14 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.13 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.12 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.11 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.10 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.9 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.8 lib/workarea/configuration/administrable/fieldset.rb
workarea-core-3.5.7 lib/workarea/configuration/administrable/fieldset.rb