Class: Terrazzo::Filter
- Inherits:
-
Object
- Object
- Terrazzo::Filter
- Defined in:
- lib/terrazzo/filter.rb
Instance Attribute Summary collapse
-
#dashboard ⇒ Object
readonly
Returns the value of attribute dashboard.
-
#filter_name ⇒ Object
readonly
Returns the value of attribute filter_name.
-
#filter_value ⇒ Object
readonly
Returns the value of attribute filter_value.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
-
#initialize(resources, dashboard, filter_name, filter_value = nil) ⇒ Filter
constructor
A new instance of Filter.
- #run ⇒ Object
Constructor Details
#initialize(resources, dashboard, filter_name, filter_value = nil) ⇒ Filter
Returns a new instance of Filter.
5 6 7 8 9 10 |
# File 'lib/terrazzo/filter.rb', line 5 def initialize(resources, dashboard, filter_name, filter_value = nil) @resources = resources @dashboard = dashboard @filter_name = filter_name&.to_sym @filter_value = filter_value end |
Instance Attribute Details
#dashboard ⇒ Object (readonly)
Returns the value of attribute dashboard.
3 4 5 |
# File 'lib/terrazzo/filter.rb', line 3 def dashboard @dashboard end |
#filter_name ⇒ Object (readonly)
Returns the value of attribute filter_name.
3 4 5 |
# File 'lib/terrazzo/filter.rb', line 3 def filter_name @filter_name end |
#filter_value ⇒ Object (readonly)
Returns the value of attribute filter_value.
3 4 5 |
# File 'lib/terrazzo/filter.rb', line 3 def filter_value @filter_value end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
3 4 5 |
# File 'lib/terrazzo/filter.rb', line 3 def resources @resources end |
Instance Method Details
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/terrazzo/filter.rb', line 12 def run return resources unless filter_name filters = dashboard.collection_filters filter_lambda = filters[filter_name] return resources unless filter_lambda if filter_lambda.arity == 1 || (filter_lambda.arity < 0 && filter_value.nil?) filter_lambda.call(resources) else filter_lambda.call(resources, filter_value) end end |