Module: Reform::Contract::PropertyMethods

Extended by:
Forwardable
Included in:
Reform::Contract
Defined in:
lib/reform/contract.rb

Instance Method Summary collapse

Instance Method Details

#collection(name, options = {}, &block) ⇒ Object



36
37
38
39
40
# File 'lib/reform/contract.rb', line 36

def collection(name, options={}, &block)
  options[:collection] = true

  property(name, options, &block)
end

#properties(names, *args) ⇒ Object



42
43
44
# File 'lib/reform/contract.rb', line 42

def properties(names, *args)
  names.each { |name| property(name, *args) }
end

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



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/reform/contract.rb', line 24

def property(name, options={}, &block)
  options[:private_name] = options.delete(:as)

  # at this point, :extend is a Form class.
  options[:features] = features if block_given?
  definition = representer_class.property(name, options, &block)
  setup_form_definition(definition) if block_given? or options[:form]

  create_accessor(name)
  definition
end

#setup_form_definition(definition) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/reform/contract.rb', line 46

def setup_form_definition(definition)
  options = {
    :form         => definition[:form] || definition[:extend].evaluate(nil), # :form is always just a Form class name.
    :pass_options => true, # new style of passing args
    :prepare      => lambda { |form, args| form }, # always just return the form without decorating.
    :representable => true, # form: Class must be treated as a typed property.
  }

  definition.merge!(options)
end