Module: Reform::Contract::PropertyMethods
- Included in:
- Reform::Contract
- Defined in:
- lib/reform/contract.rb
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
45 46 47 48 49 |
# File 'lib/reform/contract.rb', line 45 def collection(name, ={}, &block) [:collection] = true property(name, , &block) end |
#properties(names, *args) ⇒ Object
51 52 53 |
# File 'lib/reform/contract.rb', line 51 def properties(names, *args) names.each { |name| property(name, *args) } end |
#property(name, options = {}, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/reform/contract.rb', line 30 def property(name, ={}, &block) [:private_name] = .delete(:as) [:coercion_type] = .delete(:type) [:features] ||= [] [:features] += features.keys 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
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/reform/contract.rb', line 55 def setup_form_definition(definition) = { # TODO: make this a bit nicer. why do we need :form at all? :form => (definition[:extend] and definition[:extend].evaluate(nil)) || definition[:form], # :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 |