class LunaPark::Forms::SingleItem
Form object represents blank document, required to filled right, and can be performed
@example
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
Attributes
params[R]
result[R]
Public Class Methods
new(params = {})
click to toggle source
# File lib/luna_park/forms/single_item.rb, line 38 def initialize(params = {}) @params = params end
Public Instance Methods
submit()
click to toggle source
# File lib/luna_park/forms/single_item.rb, line 42 def submit if valid? fill! perform! true else false end end
Private Instance Methods
fill!()
click to toggle source
# File lib/luna_park/forms/single_item.rb, line 57 def fill! set_attributes valid_params end
perform()
click to toggle source
@abstract
# File lib/luna_park/forms/single_item.rb, line 68 def perform raise Errors::AbstractMethod end
perform!()
click to toggle source
# File lib/luna_park/forms/single_item.rb, line 61 def perform! @result = perform end