Class: SimpleFormRansack::FormProxy
- Inherits:
-
Object
- Object
- SimpleFormRansack::FormProxy
show all
- Defined in:
- lib/simple_form_ransack/form_proxy.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args) ⇒ FormProxy
Returns a new instance of FormProxy.
16
17
18
19
20
21
22
23
24
|
# File 'lib/simple_form_ransack/form_proxy.rb', line 16
def initialize(args)
@resource = args.fetch(:resource)
@object = @resource.object
@class = @resource.klass
@params = args.fetch(:params)
@form = args.fetch(:form)
raise "No params given in arguments: #{args.keys}" unless @params
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &blk) ⇒ Object
46
47
48
|
# File 'lib/simple_form_ransack/form_proxy.rb', line 46
def method_missing(method_name, *args, &blk)
@form.__send__(method_name, *args, &blk)
end
|
Class Method Details
.predicates_regex ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/simple_form_ransack/form_proxy.rb', line 2
def self.predicates_regex
unless @predicates_regex
predicates = Ransack::Configuration
.predicates
.map(&:first)
.map { |predicate| Regexp.escape(predicate) }
.join("|")
@predicates_regex = /^(.+)_(#{predicates})$/
end
@predicates_regex
end
|
Instance Method Details
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/simple_form_ransack/form_proxy.rb', line 26
def input(name, *args)
if args.last.is_a?(Hash)
opts = args.pop
else
opts = {}
end
attribute_name = real_name(name)
as = as_from_opts(attribute_name, opts)
input_html = opts.delete(:input_html) || {}
set_value(as, name, opts, input_html)
set_name(as, name, input_html)
set_label(attribute_name, opts, input_html)
opts[:required] = false unless opts.key?(:required)
opts[:input_html] = input_html
args << opts
@form.input(attribute_name, *args)
end
|