Module: Reform::Form::ActiveModel::ClassMethods
- Defined in:
- lib/reform/form/active_model.rb
Class Method Summary collapse
-
.extended(base) ⇒ Object
this module is only meant to extend (not include).
Instance Method Summary collapse
-
#model(main_model, options = {}) ⇒ Object
Set a model name for this form if the infered is wrong.
- #model_name ⇒ Object
-
#property ⇒ Object
DISCUSS: can we achieve that somehow via features in build_inline?.
- #validate(*args, &block) ⇒ Object
-
#validates(*args, &block) ⇒ Object
moved from reform as not applicable to dry.
- #validates_each(*args, &block) ⇒ Object
- #validates_with(*args, &block) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
this module is only meant to extend (not include). # DISCUSS: is this a sustainable concept?
22 23 24 25 26 27 |
# File 'lib/reform/form/active_model.rb', line 22 def self.extended(base) base.class_eval do extend Uber::InheritableAttribute inheritable_attr :model_options end end |
Instance Method Details
#model(main_model, options = {}) ⇒ Object
Set a model name for this form if the infered is wrong.
class CoverSongForm < Reform::Form
model :song
or we can setup a isolated namespace model ( which defined in isolated rails egine )
class CoverSongForm < Reform::Form
model "api/v1/song", namespace: "api"
70 71 72 |
# File 'lib/reform/form/active_model.rb', line 70 def model(main_model, ={}) self. = [main_model, ] end |
#model_name ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/reform/form/active_model.rb', line 74 def model_name if form_name = .first.to_s.camelize namespace = .last[:namespace].present? ? .last[:namespace].to_s.camelize.constantize : nil else if name form_name = name.sub(/(::)?Form$/, "") # Song::Form => "Song" namespace = nil else # anonymous forms. let's drop AM and forget about all this. form_name = "reform" namespace = nil end end active_model_name_for(form_name, namespace) end |
#property ⇒ Object
DISCUSS: can we achieve that somehow via features in build_inline?
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/reform/form/active_model.rb', line 30 def property(*) super.tap do |dfn| return dfn unless dfn[:nested] _name = dfn[:name] dfn[:nested].instance_eval do @_name = _name.singularize.camelize # this adds Form::name for AM::Validations and I18N. def name @_name end end end end |
#validate(*args, &block) ⇒ Object
49 50 51 |
# File 'lib/reform/form/active_model.rb', line 49 def validate(*args, &block) validation(name: :default, inherit: true) { validate *args, &block } end |
#validates(*args, &block) ⇒ Object
moved from reform as not applicable to dry
45 46 47 |
# File 'lib/reform/form/active_model.rb', line 45 def validates(*args, &block) validation(name: :default, inherit: true) { validates *args, &block } end |
#validates_each(*args, &block) ⇒ Object
57 58 59 |
# File 'lib/reform/form/active_model.rb', line 57 def validates_each(*args, &block) validation(name: :default, inherit: true) { validates_each *args, &block } end |
#validates_with(*args, &block) ⇒ Object
53 54 55 |
# File 'lib/reform/form/active_model.rb', line 53 def validates_with(*args, &block) validation(name: :default, inherit: true) { validates_with *args, &block } end |