Class: Reform::Contract

Inherits:
Object
  • Object
show all
Extended by:
PropertyMethods, Schema, Uber::Delegates, Uber::InheritableAttr
Includes:
ActiveModel::Validations, Setup, Validate
Defined in:
lib/reform/contract.rb,
lib/reform/contract/setup.rb

Overview

Gives you a DSL for defining the object structure and its validations.

Direct Known Subclasses

Form

Defined Under Namespace

Modules: PropertyMethods, Setup, Validate Classes: Errors, Fields

Constant Summary collapse

RESERVED_METHODS =

TODO: refactor that so we don’t need that.

[:model, :aliased_model, :fields, :mapper]

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from PropertyMethods

collection, properties, property, setup_form_definition

Methods included from Schema

schema

Methods included from Validate

#validate, #validate!

Methods included from Setup

#create_fields, #initialize, #setup_fields, #setup_representer

Methods included from Setup::Readable

#setup_options

Methods included from Setup::SetupOptions

#setup_options

Instance Attribute Details

#errorsObject

FIXME: this is needed for Rails 3.0 compatibility.



134
135
136
# File 'lib/reform/contract.rb', line 134

def errors # FIXME: this is needed for Rails 3.0 compatibility.
  @errors ||= Errors.new(self)
end

#modelObject Also known as: aliased_model

Returns the value of attribute model.



112
113
114
# File 'lib/reform/contract.rb', line 112

def model
  @model
end

Class Method Details

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



121
122
123
124
125
126
127
128
129
# File 'lib/reform/contract.rb', line 121

def self.representer(name=nil, options={}, &block)
  return representer_class.each(&block) if name == nil
  return representers[name] if representers[name] # don't run block as this representer is already setup for this form class.

  only_forms = options[:all] ? false : true
  base       = options[:superclass] || representer_class

  representers[name] = Class.new(base).each(only_forms, &block) # let user modify representer.
end

.representersObject

keeps all transformation representers for one class.



117
118
119
# File 'lib/reform/contract.rb', line 117

def self.representers # keeps all transformation representers for one class.
  @representers ||= {}
end