Module: Reform::Contract::PropertyMethods
Instance Method Summary collapse
- #collection(name, options = {}, &block) ⇒ Object
- #properties(names, *args) ⇒ Object
- #property(name, options = {}, &block) ⇒ Object
- #setup_form_definition(definition) ⇒ Object
Instance Method Details
#collection(name, options = {}, &block) ⇒ Object
36 37 38 39 40 |
# File 'lib/reform/contract.rb', line 36 def collection(name, ={}, &block) [:collection] = true property(name, , &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, ={}, &block) [:private_name] = .delete(:as) # at this point, :extend is a Form class. [:features] = features if block_given? definition = representer_class.property(name, , &block) setup_form_definition(definition) if block_given? or [: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) = { :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!() end |