Class: Listings::CustomFilterView
- Inherits:
-
Object
- Object
- Listings::CustomFilterView
- Defined in:
- lib/listings/custom_filter_view.rb
Instance Attribute Summary collapse
-
#descriptor ⇒ Object
readonly
Returns the value of attribute descriptor.
-
#listing ⇒ Object
readonly
Returns the value of attribute listing.
Instance Method Summary collapse
- #apply_filter(value) ⇒ Object
-
#initialize(listing, descriptor) ⇒ CustomFilterView
constructor
A new instance of CustomFilterView.
- #key ⇒ Object
- #partial_name ⇒ Object
- #prepare_values ⇒ Object
- #render? ⇒ Boolean
- #render_option ⇒ Object
Constructor Details
#initialize(listing, descriptor) ⇒ CustomFilterView
Returns a new instance of CustomFilterView.
6 7 8 9 |
# File 'lib/listings/custom_filter_view.rb', line 6 def initialize(listing, descriptor) @listing = listing @descriptor = descriptor end |
Instance Attribute Details
#descriptor ⇒ Object (readonly)
Returns the value of attribute descriptor.
4 5 6 |
# File 'lib/listings/custom_filter_view.rb', line 4 def descriptor @descriptor end |
#listing ⇒ Object (readonly)
Returns the value of attribute listing.
3 4 5 |
# File 'lib/listings/custom_filter_view.rb', line 3 def listing @listing end |
Instance Method Details
#apply_filter(value) ⇒ Object
19 20 21 22 23 |
# File 'lib/listings/custom_filter_view.rb', line 19 def apply_filter(value) listing.data_source.transform_items do |items| listing.instance_exec items, value, &@descriptor.proc end end |
#key ⇒ Object
15 16 17 |
# File 'lib/listings/custom_filter_view.rb', line 15 def key @descriptor.key end |
#partial_name ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/listings/custom_filter_view.rb', line 33 def partial_name if render_option.is_a?(String) render_option else raise "custom filters can only be rendered when a partial is specified" end end |
#prepare_values ⇒ Object
11 12 13 |
# File 'lib/listings/custom_filter_view.rb', line 11 def prepare_values # custom filters do not perform lookup end |
#render? ⇒ Boolean
25 26 27 28 29 30 31 |
# File 'lib/listings/custom_filter_view.rb', line 25 def render? if render_option.is_a?(String) true else render_option end end |
#render_option ⇒ Object
41 42 43 |
# File 'lib/listings/custom_filter_view.rb', line 41 def render_option @descriptor.props.fetch(:render, false) end |