Class: SimpleFormRansack::FormProxy
- Inherits:
-
Object
- Object
- SimpleFormRansack::FormProxy
- Defined in:
- lib/simple_form_ransack/form_proxy.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ FormProxy
constructor
A new instance of FormProxy.
- #input(name, *args) ⇒ Object
-
#method_missing(method_name, *args, &blk) ⇒ Object
rubocop:disable Style/MissingRespondToMissing.
Constructor Details
#initialize(args) ⇒ FormProxy
Returns a new instance of FormProxy.
22 23 24 25 26 27 28 29 |
# File 'lib/simple_form_ransack/form_proxy.rb', line 22 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
rubocop:disable Style/MissingRespondToMissing
43 44 45 |
# File 'lib/simple_form_ransack/form_proxy.rb', line 43 def method_missing(method_name, *args, &blk) # rubocop:disable Style/MissingRespondToMissing @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 20 |
# 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 .sorted_names_with_underscores .map(&:first) .map { |predicate| Regexp.escape(predicate) } .join("|") else # BazaModels support predicates = "cont|eq|gteq|lteq|gt|lt|eq_any" end @predicates_regex = /^(.+)_(#{predicates})$/ end @predicates_regex end |
Instance Method Details
#input(name, *args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/simple_form_ransack/form_proxy.rb', line 31 def input(name, *args) input_manipulator = SimpleFormRansack::InputManipulator.new( name: name, args: args, params: @params, search_key: @ransack.context.search_key, class: @class ) @form.input(input_manipulator.attribute_name, *args) end |