filter_form 0.6.2 → 0.7.0

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: d15e455964a95e853df84f34866dbbfd3453ddf8
4
- data.tar.gz: 3a39ec88bc8f534a3943b0151edf4030dc2d9852
3
+ metadata.gz: 171340b9c0fc1d7d02673af21730771c2b0418cb
4
+ data.tar.gz: ed3e5ceb3b980f7be6b180473324c5f0fbc32f1a
5
5
  SHA512:
6
- metadata.gz: caf8b95a46bde654bd666b09fdcca90254eb549143817194f2f42ba38bd76b40c4d1abe94a95a82e73d37b68921460beabc30ebf4d6e076b3875a9567eed56dd
7
- data.tar.gz: 128383934a1b6f074d97a402d79df42744ae07cff1f18e9afbd8c543718874748ba9f1cd0bc4a1d1b63ecca3e080128b0cd4f97d866e11dc5054d763289f86e6
6
+ metadata.gz: 1f6ac120444c85f9e17379f20d90785be8292ef3c8b77134955f064c646457d3fb880f8f9b44024e8760603f23adfa77b5b0b5edbde7f8bf99c29aa03f1ff31d
7
+ data.tar.gz: a77bb4a9608392182ee035c692b0ce6c6211823db6eeed231674358d1047567dde3927db2a1ab2973959b4d8b780c6ba5a5e8102502171aa55493e32071abf14
data/README.md CHANGED
@@ -36,7 +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
+ <%= f.filter_input :parents # has_many %>
40
40
  <%= f.filter_input :birthday # date %>
41
41
  <%= f.filter_input :amount # money %>
42
42
  <%= f.filter_input :married # boolean %>
@@ -48,18 +48,16 @@ In your view file:
48
48
 
49
49
  Mapping | Database Column Type | Default predicate | Generated HTML Element |
50
50
  --------------- |:------------------------------------------------|:----------------------|:--------------------------|
51
- `boolean` | `boolean` | `true` | `input[type=checkbox]` |
52
- `string` | `string` | `cont` | `input[type=text]` |
53
- `text` | `text` | `cont` | `input[type=text]` |
54
- `integer` | `integer` | `eq` | `input[type=number]` |
55
- `float` | `float` | `eq` | `input[type=number]` |
56
- `decimal` | `decimal` | `eq` | `input[type=number]` |
57
- `date` | `date` | `eq` | `input[type=text]` |
58
- `datetime` | `datetime` | `eq` | `input[type=text]` |
59
- `select` | `select` | `eq` | `select` |
60
- `belongs_to` | `belongs_to` association | `eq` | `select` |
61
- `collection` | `has_many` or `has_and_belongs_to_many` association | `eq` | `select` |
62
- `money` | `money` [monetized](https://github.com/RubyMoney/money-rails) attribute | `eq` | `input[type=number]` |
51
+ `boolean` | `boolean` | `true` | `input[type="checkbox"]` |
52
+ `string` | `string` | `cont` | `input[type="text"]` |
53
+ `text` | `text` | `cont` | `input[type="text"]` |
54
+ `integer` | `integer` | `eq` | `input[type="number"]` |
55
+ `float` | `float` | `eq` | `input[type="number"]` |
56
+ `decimal` | `decimal` | `eq` | `input[type="number"]` |
57
+ `date` | `date` | `eq` | `input[type="text"]` |
58
+ `datetime` | `datetime` | `eq` | `input[type="text"]` |
59
+ `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations | `eq` | `select` |
60
+ `money` | `money` [monetized](https://github.com/RubyMoney/money-rails) attribute | `eq` | `input[type="number"]` |
63
61
 
64
62
  ### Customization
65
63
 
@@ -14,11 +14,43 @@ module FilterForm
14
14
  end
15
15
 
16
16
  def collection
17
- options[:collection] || object.klass.uniq.pluck(attribute_name)
17
+ if options[:collection]
18
+ options[:collection]
19
+ elsif belongs_to?
20
+ attribute_name.to_s.camelize.constantize.all
21
+ elsif collection?
22
+ attribute_name.to_s.camelize.singularize.constantize.all
23
+ else
24
+ object.klass.uniq.pluck(attribute_name)
25
+ end
26
+ end
27
+
28
+ def input_attribute_name
29
+ if association
30
+ "#{ attribute_name }_id"
31
+ else
32
+ super
33
+ end
18
34
  end
19
35
 
20
36
  def input_class
21
- options[:in] == :select2 ? 'filter_form_select2' : super
37
+ if options[:in] == :select2
38
+ 'filter_form_select2'
39
+ else
40
+ super
41
+ end
42
+ end
43
+
44
+ def association
45
+ object.klass.reflections[attribute_name]
46
+ end
47
+
48
+ def belongs_to?
49
+ association && association.belongs_to?
50
+ end
51
+
52
+ def collection?
53
+ association && association.collection?
22
54
  end
23
55
  end
24
56
  end
@@ -1,8 +1,6 @@
1
1
  require 'filter_form/input_options/base'
2
2
 
3
3
  require 'filter_form/input_options/select/base'
4
- require 'filter_form/input_options/select/belongs_to'
5
- require 'filter_form/input_options/select/collection'
6
4
 
7
5
  require 'filter_form/input_options/string/base'
8
6
  require 'filter_form/input_options/string/date'
@@ -63,10 +61,6 @@ module FilterForm
63
61
  'number/base'
64
62
  when :money
65
63
  'number/money'
66
- when :belongs_to
67
- 'select/belongs_to'
68
- when :collection
69
- 'select/collection'
70
64
  when :select2
71
65
  'select/select2'
72
66
  when :boolean
@@ -76,12 +70,8 @@ module FilterForm
76
70
  end
77
71
  end
78
72
 
79
- def belongs_to?
80
- object.klass.reflections[attribute_name] && object.klass.reflections[attribute_name].belongs_to?
81
- end
82
-
83
- def collection?
84
- object.klass.reflections[attribute_name] && object.klass.reflections[attribute_name].collection?
73
+ def association?
74
+ !!object.klass.reflections[attribute_name]
85
75
  end
86
76
 
87
77
  def money?
@@ -89,10 +79,8 @@ module FilterForm
89
79
  end
90
80
 
91
81
  def attribute_type
92
- if belongs_to?
93
- :belongs_to
94
- elsif collection?
95
- :collection
82
+ if association?
83
+ :select
96
84
  elsif money?
97
85
  :money
98
86
  else
@@ -1,3 +1,3 @@
1
1
  module FilterForm
2
- VERSION = '0.6.2'
2
+ VERSION = '0.7.0'
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.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeny Li
@@ -115,8 +115,6 @@ files:
115
115
  - lib/filter_form/input_options/number/base.rb
116
116
  - lib/filter_form/input_options/number/money.rb
117
117
  - lib/filter_form/input_options/select/base.rb
118
- - lib/filter_form/input_options/select/belongs_to.rb
119
- - lib/filter_form/input_options/select/collection.rb
120
118
  - lib/filter_form/input_options/string/base.rb
121
119
  - lib/filter_form/input_options/string/date.rb
122
120
  - lib/filter_form/input_options_builder.rb
@@ -1,17 +0,0 @@
1
- module FilterForm
2
- module InputOptions
3
- module Select
4
- class BelongsTo < FilterForm::InputOptions::Select::Base
5
- private
6
-
7
- def collection
8
- options[:collection] || attribute_name.to_s.camelize.constantize.all
9
- end
10
-
11
- def input_attribute_name
12
- "#{ attribute_name }_id"
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- module FilterForm
2
- module InputOptions
3
- module Select
4
- class Collection < FilterForm::InputOptions::Select::Base
5
- private
6
-
7
- def collection
8
- options[:collection] || attribute_name.to_s.camelize.singularize.constantize.all
9
- end
10
-
11
- def input_attribute_name
12
- "#{ attribute_name }_id"
13
- end
14
- end
15
- end
16
- end
17
- end