Module: Reform::Contract::PropertyMethods
- Included in:
- Reform::Contract
- Defined in:
- lib/reform/contract.rb
Instance Method Summary collapse
- #collection(name, options = {}, &block) ⇒ Object
- #properties(*args) ⇒ Object
- #property(name, options = {}, &block) ⇒ Object
- #setup_form_definition(definition) ⇒ Object
Instance Method Details
#collection(name, options = {}, &block) ⇒ Object
73 74 75 76 77 |
# File 'lib/reform/contract.rb', line 73 def collection(name, ={}, &block) [:collection] = true property(name, , &block) end |
#properties(*args) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/reform/contract.rb', line 63 def properties(*args) = args. if args.first.is_a? Array # TODO: REMOVE in 2.0. warn "[Reform] Deprecation: Please pass a list of names instead of array to ::properties, like `properties :title, :id`." args = args.first end args.each { |name| property(name, .dup) } end |
#property(name, options = {}, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/reform/contract.rb', line 31 def property(name, ={}, &block) deprecate_as!() [:private_name] = .delete(:from) [:coercion_type] = .delete(:type) [:features] ||= [] [:features] += features.keys if block_given? [:pass_options] = true # readable and writeable is true as it's not == false if reform_2_0 if .delete(:virtual) [:_readable] = false [:_writeable] = false else [:_readable] = .delete(:readable) [:_writeable] = .delete(:writeable) end else # TODO: remove me in 2.0. deprecate_virtual_and_empty!() end validates(name, .delete(:validates).dup) if [:validates] 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
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/reform/contract.rb', line 79 def setup_form_definition(definition) = { # TODO: make this a bit nicer. why do we need :form at all? :form => (definition.representer_module) || 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 |