filter_form 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd5243daad11ce3e28c7254adc4b38c1d074a832
4
- data.tar.gz: 25b9b90af41360d9cde068a1776917c969c3a7a3
3
+ metadata.gz: a83442fb7f60aefce93393a49763bb4d66495b6e
4
+ data.tar.gz: 2ded8529b6e92cecce469d4b33b5153627e8a3b7
5
5
  SHA512:
6
- metadata.gz: acbf8a3dfd3efd8321011eeb3cab40a6a1992257b1c36bd38c626da42efe3964a5325079e48e615b3af98f3b5fe328ff3cfacb48a6b4b363f54da586ca8bb96f
7
- data.tar.gz: ea9025c3daf99539f0358fef095657e0fd09da526aa579de25dfdf8366123ddac2c62e2c1de6b081fcac9d2af36ece9cd55d7d95a426d8c6e97e6aadbb36eb72
6
+ metadata.gz: 9a5c647796b8f95a916084c1ebe3268677c26a496e106576ef6634b45eb72782e22a502aeeabfd37e9fc716f43cbf457dae5447338ef9786b27a9e59bdc326b3
7
+ data.tar.gz: b3982e9af2e8457750805d14a0be2418aa1e2419eeac7e7d8ffc61f85cb4b0b2a3a5d24875fff1911224c593e59298d7f0680c0eaaba27a2f3c6fabde5fe7647
data/README.md CHANGED
@@ -36,6 +36,7 @@ In your view file:
36
36
  <%= f.filter_input :name # string %>
37
37
  <%= f.filter_input :age # integer %>
38
38
  <%= f.filter_input :city # belongs_to %>
39
+ <%= f.filter_input :parents # collection %>
39
40
  <%= f.filter_input :birthday # date %>
40
41
  <%= f.filter_input :amount # money %>
41
42
  <%= f.button :submit %>
@@ -51,6 +52,7 @@ In your view file:
51
52
  `datetime` | `datetime` | `eq` | `input[type=text]` |
52
53
  `date` | `date` | `eq` | `input[type=text]` |
53
54
  `belongs_to` | `belongs_to` association | `eq` | `select` |
55
+ `collection` | `has_many` or `has_and_belongs_to_many` association | `eq` | `select` |
54
56
  `money` | `money` [monetized](https://github.com/RubyMoney/money-rails) attribute | `eq` | `input[type=text]` |
55
57
 
56
58
  ### Customization
@@ -0,0 +1,25 @@
1
+ module FilterForm
2
+ module InputOptions
3
+ module Select
4
+ class Collection < FilterForm::InputOptions::Select::Base
5
+ private
6
+
7
+ def object_condition
8
+ object.base.conditions.select { |c| c.a.first.name == custom_attribute_name }.first
9
+ end
10
+
11
+ def collection
12
+ options[:collection] || attribute_name.to_s.camelize.singularize.constantize.all
13
+ end
14
+
15
+ def input_name
16
+ "q[#{ custom_attribute_name }_#{ predicate }]"
17
+ end
18
+
19
+ def custom_attribute_name
20
+ "#{ attribute_name }_id"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -2,6 +2,7 @@ require 'filter_form/input_options/base'
2
2
 
3
3
  require 'filter_form/input_options/select/base'
4
4
  require 'filter_form/input_options/select/belongs_to'
5
+ require 'filter_form/input_options/select/collection'
5
6
 
6
7
  require 'filter_form/input_options/string/base'
7
8
  require 'filter_form/input_options/string/date'
@@ -56,6 +57,8 @@ module FilterForm
56
57
  'string/money'
57
58
  when :belongs_to
58
59
  'select/belongs_to'
60
+ when :collection
61
+ 'select/collection'
59
62
  when :select2
60
63
  'select/select2'
61
64
  else
@@ -67,6 +70,10 @@ module FilterForm
67
70
  object.klass.reflections[attribute_name] && object.klass.reflections[attribute_name].belongs_to?
68
71
  end
69
72
 
73
+ def collection?
74
+ object.klass.reflections[attribute_name] && object.klass.reflections[attribute_name].collection?
75
+ end
76
+
70
77
  def money?
71
78
  object.klass.columns_hash["#{ attribute_name }_cents"].present?
72
79
  end
@@ -74,6 +81,8 @@ module FilterForm
74
81
  def attribute_type
75
82
  if belongs_to?
76
83
  :belongs_to
84
+ elsif collection?
85
+ :collection
77
86
  elsif money?
78
87
  :money
79
88
  else
@@ -1,3 +1,3 @@
1
1
  module FilterForm
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filter_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeny Li
@@ -113,6 +113,7 @@ files:
113
113
  - lib/filter_form/input_options/base.rb
114
114
  - lib/filter_form/input_options/select/base.rb
115
115
  - lib/filter_form/input_options/select/belongs_to.rb
116
+ - lib/filter_form/input_options/select/collection.rb
116
117
  - lib/filter_form/input_options/string/base.rb
117
118
  - lib/filter_form/input_options/string/date.rb
118
119
  - lib/filter_form/input_options/string/money.rb