filter_form 0.7.0 → 0.7.1

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: 171340b9c0fc1d7d02673af21730771c2b0418cb
4
- data.tar.gz: ed3e5ceb3b980f7be6b180473324c5f0fbc32f1a
3
+ metadata.gz: 7dcaf4e227c17f563b101cefe9a484d9fd066d48
4
+ data.tar.gz: 7bdd04c0838a27f3e04789a51de8b73e0d4b3d80
5
5
  SHA512:
6
- metadata.gz: 1f6ac120444c85f9e17379f20d90785be8292ef3c8b77134955f064c646457d3fb880f8f9b44024e8760603f23adfa77b5b0b5edbde7f8bf99c29aa03f1ff31d
7
- data.tar.gz: a77bb4a9608392182ee035c692b0ce6c6211823db6eeed231674358d1047567dde3927db2a1ab2973959b4d8b780c6ba5a5e8102502171aa55493e32071abf14
6
+ metadata.gz: 2f17dca9f965ebf77df3b5b2c7cbb6982cd706e0f41f20573d24c0076aba27896f769124aefac747d9ff03e401a0d2fb4f5c82a1938fdbaeb175f7c427c0dee7
7
+ data.tar.gz: ccfbb999edd00621a83ff4e968816572cbab2667ef9c40c340f6205b78ad0568de7e8e305b88963442c1b5e08d2669c1cd23a28b9aef2938b24531933ec82310
data/README.md CHANGED
@@ -33,13 +33,13 @@ In your view file:
33
33
 
34
34
  ```erb
35
35
  <%= filter_form_for @q do |f| %>
36
+ <%= f.filter_input :married # boolean %>
36
37
  <%= f.filter_input :name # string %>
37
38
  <%= f.filter_input :age # integer %>
39
+ <%= f.filter_input :birthday # date %>
38
40
  <%= f.filter_input :city # belongs_to %>
39
41
  <%= f.filter_input :parents # has_many %>
40
- <%= f.filter_input :birthday # date %>
41
42
  <%= f.filter_input :amount # money %>
42
- <%= f.filter_input :married # boolean %>
43
43
  <%= f.button :submit %>
44
44
  <% end %>
45
45
  ```
@@ -3,7 +3,9 @@ module FilterForm
3
3
  class Base
4
4
  include ActiveModel::Model
5
5
 
6
- attr_accessor :attribute_name, :object, :predicate, :options
6
+ DEFAULT_PREDICATE = nil
7
+
8
+ attr_accessor :attribute_name, :object, :custom_predicate, :options
7
9
 
8
10
  def simple_form_options
9
11
  default_options.merge(additional_options).merge(options)
@@ -81,6 +83,10 @@ module FilterForm
81
83
  def input_attribute_name
82
84
  attribute_name
83
85
  end
86
+
87
+ def predicate
88
+ custom_predicate || self.class::DEFAULT_PREDICATE
89
+ end
84
90
  end
85
91
  end
86
92
  end
@@ -2,6 +2,8 @@ module FilterForm
2
2
  module InputOptions
3
3
  module Checkbox
4
4
  class Base < FilterForm::InputOptions::Base
5
+ DEFAULT_PREDICATE = :true
6
+
5
7
  private
6
8
 
7
9
  def additional_options
@@ -2,6 +2,8 @@ module FilterForm
2
2
  module InputOptions
3
3
  module Number
4
4
  class Base < FilterForm::InputOptions::Base
5
+ DEFAULT_PREDICATE = :eq
6
+
5
7
  private
6
8
 
7
9
  def additional_options
@@ -2,6 +2,8 @@ module FilterForm
2
2
  module InputOptions
3
3
  module Select
4
4
  class Base < FilterForm::InputOptions::Base
5
+ DEFAULT_PREDICATE = :eq
6
+
5
7
  private
6
8
 
7
9
  def additional_options
@@ -2,6 +2,8 @@ module FilterForm
2
2
  module InputOptions
3
3
  module String
4
4
  class Base < FilterForm::InputOptions::Base
5
+ DEFAULT_PREDICATE = :cont
6
+
5
7
  private
6
8
 
7
9
  def additional_options
@@ -17,7 +17,7 @@ module FilterForm
17
17
  attr_accessor :attribute_name, :object, :custom_predicate, :custom_type
18
18
 
19
19
  def build(options)
20
- input_options_class.new(attribute_name: attribute_name, object: object, predicate: predicate, options: options).simple_form_options
20
+ input_options_class.new(attribute_name: attribute_name, object: object, custom_predicate: custom_predicate, options: options).simple_form_options
21
21
  end
22
22
 
23
23
  private
@@ -34,19 +34,6 @@ module FilterForm
34
34
  "FilterForm::InputOptions::#{ class_name }".constantize
35
35
  end
36
36
 
37
- def predicate
38
- return custom_predicate if custom_predicate
39
-
40
- case type
41
- when :string
42
- :cont
43
- when :boolean
44
- :true
45
- else
46
- :eq
47
- end
48
- end
49
-
50
37
  def type
51
38
  custom_type ? map_type(custom_type) : map_type(attribute_type)
52
39
  end
@@ -1,3 +1,3 @@
1
1
  module FilterForm
2
- VERSION = '0.7.0'
2
+ VERSION = '0.7.1'
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.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeny Li