class LunaPark::Forms::Simple

Form object represents blank document, required to filled right, and can be performed

@example with default behavior

class MyForm < LunaPark::Forms::SingleItem
  validation MyValidator # respond to .validate, #valid?, #errors, #valid_params

  def perform(valid_params)
    "Performed #{valid_params[:foo]}"
  end
end

form = MyForm.new({ foo: 'Foo', excess: 'Excess' })

if form.submit
  form.result # => 'Performed Foo'
else
  form.errors # => { foo: ['is wrong'] }
end

@example without default behavior

class MyForm < LunaPark::Forms::SingleItem
  validation MyValidator # respond to .validate, #valid?, #errors, #valid_params
end

form = MyForm.new({ foo: 'Foo', excess: 'Excess' })

if form.submit
  form.result # => { foo: 'Foo' }
else
  form.errors # => { foo: ['is wrong'] }
end

Attributes

params[R]
result[R]

Public Class Methods

new(params = {}) click to toggle source
# File lib/luna_park/forms/simple.rb, line 46
def initialize(params = {})
  @params = params
end

Public Instance Methods

submit() click to toggle source
# File lib/luna_park/forms/simple.rb, line 50
def submit
  if valid?
    perform!
    true
  else false
  end
end

Private Instance Methods

perform(valid_params) click to toggle source

@abstract

# File lib/luna_park/forms/simple.rb, line 71
def perform(valid_params)
  valid_params
end
perform!() click to toggle source
# File lib/luna_park/forms/simple.rb, line 64
def perform!
  @result = perform(valid_params)
end