Sha256: 8df7209ab9d4bb3168f0fc3655c56dc72d878b028bdf3d4167c83d2722f72973

Contents?: true

Size: 698 Bytes

Versions: 10

Compression:

Stored size: 698 Bytes

Contents

class Tramway::Core::ExtendableForm
  class << self
    def new(name, *more_properties)
      if Object.const_defined? name
        name.constantize
      else
        Object.const_set(name, Class.new(::Tramway::Core::ApplicationForm) do
          define_method 'submit' do |params|
            model.values ||= {}
            model.values = params.permit!.to_h.reduce({}) do |hash, pair|
              hash.merge! pair[0] => pair[1]
            end
            super params
          end

          more_properties.each do |property|
            define_method property do 
              model.values[property] if model.values
            end
          end
        end)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tramway-core-1.5.5.2 app/forms/tramway/core/extendable_form.rb
tramway-core-1.5.5.1 app/forms/tramway/core/extendable_form.rb
tramway-core-1.5.5 app/forms/tramway/core/extendable_form.rb
tramway-core-1.5.4 app/forms/tramway/core/extendable_form.rb
tramway-core-1.5.3 app/forms/tramway/core/extendable_form.rb
tramway-core-1.5.2 app/forms/tramway/core/extendable_form.rb
tramway-core-1.5.1 app/forms/tramway/core/extendable_form.rb
tramway-core-1.5 app/forms/tramway/core/extendable_form.rb
tramway-core-1.4.1 app/forms/tramway/core/extendable_form.rb
tramway-core-1.4 app/forms/tramway/core/extendable_form.rb