Module: Formalism::ModelForms::Base::ClassMethods

Includes:
Memery
Defined in:
lib/formalism/model_forms/_base.rb

Overview

Module for Base form class methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#primary_field_nameObject

Returns the value of attribute primary_field_name.



44
45
46
# File 'lib/formalism/model_forms/_base.rb', line 44

def primary_field_name
  @primary_field_name
end

Instance Method Details

#included(something) ⇒ Object



39
40
41
42
# File 'lib/formalism/model_forms/_base.rb', line 39

def included(something)
	super
	something.primary_field_name = primary_field_name
end

#inherited(form) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/formalism/model_forms/_base.rb', line 27

def inherited(form)
	super

	form.primary_field_name = primary_field_name

	return if form.instance_name == :model
	return if form.method_defined?(form.instance_name.to_s)

	form.alias_method form.instance_name, :instance
	form.alias_method "#{form.instance_name}=", :instance=
end

#primary_field(name, *args, **kwargs) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/formalism/model_forms/_base.rb', line 46

def primary_field(name, *args, **kwargs)
	remove_field primary_field_name if primary_field_name

	field name, *args, **kwargs

	self.primary_field_name = name
end

#remove_field(name) ⇒ Object



54
55
56
57
58
# File 'lib/formalism/model_forms/_base.rb', line 54

def remove_field(name)
	super

	self.primary_field_name = nil if name == primary_field_name
end