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.
21
22
23
24
25
26
27
28
|
# File 'lib/simple_form_ransack/form_proxy.rb', line 21
def initialize(args)
@ransack = args.fetch(:ransack)
@class = @ransack.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
41
42
43
|
# File 'lib/simple_form_ransack/form_proxy.rb', line 41
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
15
16
17
18
19
|
# File 'lib/simple_form_ransack/form_proxy.rb', line 2
def self.predicates_regex
unless @predicates_regex
if Object.const_defined?(:Ransack)
predicates = Ransack::Configuration
.predicates
.map(&:first)
.map { |predicate| Regexp.escape(predicate) }
.join("|")
else
predicates = "cont|eq|gteq|lteq|gt|lt|eq_any"
end
@predicates_regex = /^(.+)_(#{predicates})$/
end
@predicates_regex
end
|
Instance Method Details
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/simple_form_ransack/form_proxy.rb', line 30
def input(name, *args)
input_manipulator = SimpleFormRansack::InputManipulator.new(
name: name,
args: args,
params: @params,
class: @class
)
@form.input(input_manipulator.attribute_name, *args)
end
|