Class: Reform::Contract

Inherits:
Disposable::Twin
  • Object
show all
Includes:
Disposable::Twin::Sync, Expose, Readonly, Validate, Validation
Defined in:
lib/reform/contract.rb,
lib/reform/result.rb,
lib/reform/contract/validate.rb,
lib/reform/contract/custom_error.rb

Overview

Define your form structure and its validations. Instantiate it with a model, and then validate this object graph.

Direct Known Subclasses

Form

Defined Under Namespace

Modules: Readonly, Validate Classes: CustomError, Result

Constant Summary

Constants included from Validation

Validation::NoValidationLibraryError

Class Method Summary collapse

Methods included from Readonly

#options_for, #readonly?

Methods included from Validation

included, #valid?

Methods included from Validate

#custom_errors, #errors, #initialize, #to_result, #validate, #validate!

Class Method Details

.default_nested_classObject



13
14
15
# File 'lib/reform/contract.rb', line 13

def self.default_nested_class
  Contract
end

.properties(*args) ⇒ Object



29
30
31
32
# File 'lib/reform/contract.rb', line 29

def self.properties(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  args.each { |name| property(name, options.dup) }
end

.property(name, options = {}, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/reform/contract.rb', line 17

def self.property(name, options = {}, &block)
  if twin = options.delete(:form)
    options[:twin] = twin
  end

  if validates_options = options[:validates]
    validates name, validates_options
  end

  super
end