Class: Forminator::Step

Inherits:
Object
  • Object
show all
Includes:
Hanami::Validations
Defined in:
lib/forminator/step.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



11
12
13
# File 'lib/forminator/step.rb', line 11

def object
  @object
end

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/forminator/step.rb', line 11

def params
  @params
end

Class Method Details

.call(object, params, **options) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/forminator/step.rb', line 13

def self.call(object, params, **options)
  step = new(params)
  validity = step.valid?
  if validity && step.persist?
    step.persist(object: object, persist: options[:persist])
  end

  [{ valid: validity }, params]
end

Instance Method Details

#persist(object:, persist: nil) ⇒ Object



31
32
33
34
# File 'lib/forminator/step.rb', line 31

def persist(object:, persist: nil)
  persist&.call(object) ||
  Forminator.config.persist.call(object)
end

#persist?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/forminator/step.rb', line 27

def persist?
  false
end

#valid?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/forminator/step.rb', line 23

def valid?
  validate.success?
end