Class: LunaPark::Forms::SingleItem

Inherits:
Object
  • Object
show all
Includes:
Extensions::Attributable, Extensions::Validatable
Defined in:
lib/luna_park/forms/single_item.rb

Overview

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

Examples:

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

  def perform
    'PerformResult'
  end

  def foo_bar=(foo_bar)
    @foo_bar = foo_bar
  end
end

form = MyForm.new({ foo_bar: {} })

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Extensions::Validatable

included

Constructor Details

#initialize(params = {}) ⇒ SingleItem

Returns a new instance of SingleItem.



38
39
40
# File 'lib/luna_park/forms/single_item.rb', line 38

def initialize(params = {})
  @params = params
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



36
37
38
# File 'lib/luna_park/forms/single_item.rb', line 36

def result
  @result
end

Instance Method Details

#submitObject



42
43
44
45
46
47
48
49
# File 'lib/luna_park/forms/single_item.rb', line 42

def submit
  if valid?
    fill!
    perform!
    true
  else false
  end
end