Module: Reform::Form::ModelReflections

Defined in:
lib/reform/form/model_reflections.rb

Overview

ModelReflections will be the interface between the form object and form builders like simple_form.

This module is meant to collect all dependencies simple_form needs in addition to the ActiveModel ones. Goal is to collect all methods and define a reflection API so simple_form works with all ORMs and Reform doesn’t have to “guess” what simple_form and other form helpers need.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
# File 'lib/reform/form/model_reflections.rb', line 7

def self.included(base)
  base.extend ClassMethods
  base.register_feature self # makes it work in nested forms.
end

Instance Method Details

#column_for_attribute(name) ⇒ Object

Delegate column for attribute to the model to support simple_form’s attribute type interrogation.



22
23
24
# File 'lib/reform/form/model_reflections.rb', line 22

def column_for_attribute(name)
  model_for_property(name).column_for_attribute(name)
end

#defined_enumsObject



30
31
32
33
34
# File 'lib/reform/form/model_reflections.rb', line 30

def defined_enums
  return model.defined_enums unless is_a?(Reform::Form::Composition)

  model.each.with_object({}) { |m,h| h.merge! m.defined_enums }
end

#has_attribute?(name) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/reform/form/model_reflections.rb', line 26

def has_attribute?(name)
  model_for_property(name).has_attribute?(name)
end