upnxt-ransack 0.0.1 → 0.0.2

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: 56157dc57f7873dcc5f8af28664a79b903786dc7
4
- data.tar.gz: fe4eaba2dd21e6142a6eefca0efd52e4f156873e
3
+ metadata.gz: 3c2a88b81d06252dd91c89c313089557acfabc4f
4
+ data.tar.gz: f79536b3aed41cadcfef79c228f646d05a31d23e
5
5
  SHA512:
6
- metadata.gz: 5b1d3a85da7c693d4c708b155994b50b3e52bcab0253a70c64b14b8df330932448df55132bc37ee659162b3d9fda792653640db6c2377186b60c47fa7c0e83fe
7
- data.tar.gz: 76a1678209e14d2839fe2c3c32183416c71fdb34937ea24b3b3bc1a337a5eb635b35d2a01acfe3276d91b311cf4ddc824c374ba964bb97b76998ea6839a2a616
6
+ metadata.gz: b60fc519ba713232a5ea1bbe3f8305cb89d7d6f441e12d9477bc2d3b514303e0004e1d876b39816f47634898f779e7f310a0c92c5608e4bd162f69a18c1de763
7
+ data.tar.gz: 290ca016f8461887115813d553958b6f465db2f01bfd1f239e7c7aed1320048ad8ead6666b9d1322fe5933a83594448cae054bf2092c9f745acc2a3fa31e13bb
@@ -0,0 +1,36 @@
1
+ module Ransack
2
+ class Search
3
+ alias :old_initializer :initialize
4
+
5
+ def initialize(object, params = {}, options = {})
6
+ params.each do |str, _|
7
+ str = str.to_s
8
+ Predicate.detect_and_strip_from_string!(str.to_s)
9
+ assoc = convert_to_associations(object, str)
10
+ last = assoc.pop
11
+ attr_name = last.last
12
+ prev_class_sym = last.first.name.underscore.to_sym
13
+ prev_assoc_sym = nil
14
+ assoc.reverse.each do |klass, str|
15
+ assoc_sym = str.gsub(Regexp.new("_#{attr_name}\\z"), '').to_sym
16
+ klass.has_one(assoc_sym, through: prev_class_sym, source: prev_assoc_sym) unless klass.reflections.keys.include?(assoc_sym)
17
+ prev_assoc_sym = assoc_sym
18
+ prev_class_sym = klass.name.underscore.to_sym
19
+ end
20
+ end
21
+
22
+ old_initializer(object, params, options)
23
+ end
24
+
25
+ private
26
+ def convert_to_associations(klass, str)
27
+ klass.reflections.each do |name, reflection|
28
+ if str.start_with? name.to_s
29
+ result = convert_to_associations(reflection.class_name.constantize, str.sub("#{name.to_s}_", ''))
30
+ return [[klass, str]].concat(result) if result
31
+ end
32
+ end
33
+ return [[klass, str]] if klass.attribute_names.include?(str)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,6 @@
1
+ module Upnxt
2
+ module Ransack
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  module Upnxt
2
2
  module Ransack
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upnxt-ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - bert bruynooghe
@@ -33,8 +33,10 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - MIT-LICENSE
35
35
  - Rakefile
36
- - lib/ransack/version.rb
36
+ - config/initializers/ransack.rb
37
37
  - lib/upnxt-ransack.rb
38
+ - lib/upnxt/ransack/engine.rb
39
+ - lib/upnxt/ransack/version.rb
38
40
  homepage: https://github.com/UP-nxt/upnxt-ransack
39
41
  licenses:
40
42
  - MIT