simple_form_ransack 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a53539a283d1fd5d6f63466094e28dc14e05156a
4
- data.tar.gz: 013ce7640a353f2d85751bbcb32f6e1ee8bf2be1
3
+ metadata.gz: 908f1e7b0caf9a74d9afd4ace8b8eb2bd59f4662
4
+ data.tar.gz: 733e44844b4490f02a83c9796763a55bc897abf7
5
5
  SHA512:
6
- metadata.gz: 5b28ce42867295cc361f75df977cca69b5142010adb02373ae286008efe394e78ad5fc3a94029b64c837c981a1329f391215392ee425649ce63a63a1ce3e076e
7
- data.tar.gz: 573d7e113de7e1ae47ad260b6319f0a7515b97decbfdedcaf68c83e60254bf26c9b3662b41d366a711fb274920103677c063c27ac14ffc825d1f7bec5e30aa38
6
+ metadata.gz: 97128aa38fa68a4dfed2bc346ea2f6496b5f48e5bc9f74a0977704469a6badb9711f87aeb51fbb6f800154e4988f754bf03a90db56ca69b29636a9408e3928a3
7
+ data.tar.gz: 0cf66c6a840b84598afab7d486da5c44e9269bc168929ff4e024a53af3afbe9d9b1e57673b1a418e9467205cde9fde63171e3b7fc86ae23f76446432fa3b6c79
@@ -16,16 +16,17 @@ class SimpleFormRansack::FormProxy
16
16
  opts = {}
17
17
  end
18
18
 
19
- match = name.to_s.match(/^(.+)_(eq|cont|eq_any)$/)
20
- if match
21
- attribute_name = match[1]
22
- else
23
- raise "Couldn't figure out attribute name from: #{name}"
24
- end
19
+ attribute_name = real_name(name, opts)
20
+ as = as_from_opts(opts)
25
21
 
26
22
  input_html = opts.delete(:input_html) || {}
27
23
  input_html[:name] = "q[#{name}]" unless input_html.key?(:name)
28
- input_html[:value] = @params[name] if !input_html.key?(:value) && @params[name]
24
+
25
+ if as == "select"
26
+ opts[:selected] = @params[name] if !input_html.key?(:selected) && @params[name]
27
+ else
28
+ input_html[:value] = @params[name] if !input_html.key?(:value) && @params[name]
29
+ end
29
30
 
30
31
  opts[:input_html] = input_html
31
32
  opts[:required] = false unless opts.key?(:required)
@@ -37,4 +38,25 @@ class SimpleFormRansack::FormProxy
37
38
  def method_missing(method_name, *args, &blk)
38
39
  @form.__send__(method_name, *args, &blk)
39
40
  end
41
+
42
+ private
43
+
44
+ def as_from_opts(opts)
45
+ if opts[:as].present?
46
+ return opts[:as].to_s
47
+ elsif opts[:collection]
48
+ return "select"
49
+ end
50
+
51
+ return "text"
52
+ end
53
+
54
+ def real_name(name, opts)
55
+ match = name.to_s.match(/^(.+)_(eq|cont|eq_any)$/)
56
+ if match
57
+ return match[1]
58
+ else
59
+ raise "Couldn't figure out attribute name from: #{name}"
60
+ end
61
+ end
40
62
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleFormRansack
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen