Class: SimpleFormStrongParameters::FormProxy
- Inherits:
-
Object
- Object
- SimpleFormStrongParameters::FormProxy
show all
- Defined in:
- lib/form_proxy.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args) ⇒ FormProxy
Returns a new instance of FormProxy.
6
7
8
9
|
# File 'lib/form_proxy.rb', line 6
def initialize args
@args = args
@object = args[:object]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &blk) ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/form_proxy.rb', line 18
def method_missing name, *args, &blk
if name == :input
attribute_name = args[0]
register_parameter(attribute_name)
end
@simple_form.__send__(name, *args, &blk)
end
|
Instance Attribute Details
Returns the value of attribute simple_form.
4
5
6
|
# File 'lib/form_proxy.rb', line 4
def simple_form
@simple_form
end
|
Instance Method Details
#namespace ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'lib/form_proxy.rb', line 44
def namespace
if @object.is_a? ActiveRecord::Base
return StringCases.camel_to_snake(@object.class.name).to_sym
elsif @object.is_a? Symbol
return @object
else
raise "Doesn't know how to handle: #{@object.class.name}"
end
end
|
#session_var=(session_var) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/form_proxy.rb', line 11
def session_var=(session_var)
@session_var = session_var
@session_var[:attributes] = []
@session_var[:write_namespace] = write_namespace
@session_var[:subs] = {}
end
|
#simple_fields_for(*args) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/form_proxy.rb', line 27
def simple_fields_for *args
fields_namespace = args[0]
fields_session_var = {}
@simple_form.simple_fields_for *args do |fields_simple_form|
proxy = SimpleFormStrongParameters::FormProxy.new(object: fields_namespace)
proxy.simple_form = fields_simple_form
proxy.session_var = fields_session_var
begin
yield proxy
ensure
@session_var[:subs][proxy.namespace] = fields_session_var
end
end
end
|
#write_namespace ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/form_proxy.rb', line 54
def write_namespace
if @object.is_a? ActiveRecord::Base
if @args[:first]
return StringCases.camel_to_snake(@object.class.name).to_sym
end
class_name = StringCases.camel_to_snake(@object.class.name).pluralize
namespace = "#{class_name}_attributes".to_sym
return namespace
elsif @object.is_a? Symbol
return @object
else
raise "Doesn't know how to handle: #{@object.class.name}"
end
end
|