Class: Reform::Contract

Inherits:
Disposable::Twin
  • Object
show all
Includes:
Disposable::Twin::Sync, Expose, Readonly, Validate, Validation
Defined in:
lib/reform/contract.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: Errors

Instance Attribute Summary

Attributes included from Validate

#errors

Class Method Summary collapse

Methods included from Readonly

#options_for, #readonly?

Methods included from Validation

included, #valid?

Methods included from Validate

#initialize, #validate, #validate!

Class Method Details

.default_nested_classObject



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

def self.default_nested_class
  Contract
end

.properties(*args) ⇒ Object

FIXME: test me.



31
32
33
34
# File 'lib/reform/contract.rb', line 31

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



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

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