Sha256: 13cf5153f2a2742421037289bbcedc1fef38b72035df9f806122687603a50a3e

Contents?: true

Size: 779 Bytes

Versions: 4

Compression:

Stored size: 779 Bytes

Contents

module DynamicScaffold
  class FormBuilder
    def initialize(config)
      @config = config
      @items = []
      @permit_params = []
    end

    def items
      if @items.empty?
        @config.model.column_names.each do |column|
          type = :text_field
          type = :hidden_field if @config.scope && @config.scope.include?(column.to_sym)
          @items << Form::Item::SingleOption.new(@config, type, column)
        end
      end
      @items
    end

    def permit_params(*params)
      if !params.empty?
        @permit_params.concat(params)
        self
      else
        @permit_params
      end
    end

    def item(type, *args, &block)
      item = Form::Item::Base.create(@config, type, *args, &block)
      @items << item
      item
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dynamic_scaffold-1.1.2 lib/dynamic_scaffold/form_builder.rb
dynamic_scaffold-1.1.1 lib/dynamic_scaffold/form_builder.rb
dynamic_scaffold-1.1.0 lib/dynamic_scaffold/form_builder.rb
dynamic_scaffold-1.0.0 lib/dynamic_scaffold/form_builder.rb