Class: SlimFormObject::Base
- Inherits:
-
Object
- Object
- SlimFormObject::Base
show all
- Extended by:
- HelperMethods
- Includes:
- ActiveModel::Model, HelperMethods
- Defined in:
- lib/slim_form_object/processing.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
apply_expression_text, get_association, get_class_of_snake_model_name, get_self_object, snake, to_bind_models
Constructor Details
#initialize(params: {}) ⇒ Base
Returns a new instance of Base.
70
71
72
73
74
75
76
|
# File 'lib/slim_form_object/processing.rb', line 70
def initialize(params: {})
require_extensions
self.params = params
get_or_add_default_objects
default_settings
self.after_initialize_block.call(self)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/slim_form_object/processing.rb', line 62
def method_missing(name, *args, &block)
if name[/_ids$/]
model_name, attr_name = get_model_and_method_names(name)
return self.send(model_name.to_sym).send(attr_name.to_sym)
end
super(name, args, block)
end
|
Class Attribute Details
.base_module ⇒ Object
Returns the value of attribute base_module.
10
11
12
|
# File 'lib/slim_form_object/processing.rb', line 10
def base_module
@base_module
end
|
Instance Attribute Details
#array_objects_for_save ⇒ Object
Returns the value of attribute array_objects_for_save.
7
8
9
|
# File 'lib/slim_form_object/processing.rb', line 7
def array_objects_for_save
@array_objects_for_save
end
|
#data_for_save ⇒ Object
Returns the value of attribute data_for_save.
7
8
9
|
# File 'lib/slim_form_object/processing.rb', line 7
def data_for_save
@data_for_save
end
|
#params ⇒ Object
Returns the value of attribute params.
7
8
9
|
# File 'lib/slim_form_object/processing.rb', line 7
def params
@params
end
|
Class Method Details
.define_array_of_models(name, args) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/slim_form_object/processing.rb', line 28
def define_array_of_models(name, args)
self.instance_eval do
define_method(name) { args }
end
make_methods_for_objects_of(args)
end
|
.delegate_models_attributes(models) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/slim_form_object/processing.rb', line 41
def delegate_models_attributes(models)
models.each do |model|
model.column_names.each do |attr|
delegate attr.to_sym, "#{attr}=".to_sym, to: snake(model.to_s).to_sym, prefix: true
end
end
end
|
.init_single_models(*args) ⇒ Object
Also known as:
init_models
16
17
18
|
# File 'lib/slim_form_object/processing.rb', line 16
def init_single_models(*args)
define_array_of_models(:array_of_all_models, args)
end
|
.make_methods_for_objects_of(models) ⇒ Object
35
36
37
38
39
|
# File 'lib/slim_form_object/processing.rb', line 35
def make_methods_for_objects_of(models)
models.each{ |model| attr_accessor snake(model.to_s).to_sym }
delegate_models_attributes(models)
end
|
.not_save_empty_object_for(*args) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/slim_form_object/processing.rb', line 21
def not_save_empty_object_for(*args)
args.each { |model| raise "#{model.to_s} - type is not a Class" if model.class != Class }
self.instance_eval do
define_method(:array_models_which_not_save_if_empty) { args }
end
end
|
.set_model_name(name) ⇒ Object
12
13
14
|
# File 'lib/slim_form_object/processing.rb', line 12
def set_model_name(name)
define_method(:model_name) { ActiveModel::Name.new(self, nil, name) }
end
|
Instance Method Details
#apply_parameters ⇒ Object
Also known as:
submit
79
80
81
82
|
# File 'lib/slim_form_object/processing.rb', line 79
def apply_parameters
apply
self
end
|
#array_all_objects_for_save ⇒ Object
98
99
100
|
# File 'lib/slim_form_object/processing.rb', line 98
def array_all_objects_for_save
array_objects_for_save ||= get_or_add_default_objects
end
|
#save ⇒ Object
85
86
87
|
# File 'lib/slim_form_object/processing.rb', line 85
def save
Saver.new(self).save
end
|
#save! ⇒ Object
89
90
91
|
# File 'lib/slim_form_object/processing.rb', line 89
def save!
Saver.new(self).save!
end
|
#validation_models ⇒ Object
93
94
95
96
|
# File 'lib/slim_form_object/processing.rb', line 93
def validation_models
Validator.new(self).validate_form_object
end
|