Class: SearchScope::FilterScope
- Inherits:
-
Object
- Object
- SearchScope::FilterScope
- Defined in:
- lib/search_scope.rb
Instance Attribute Summary collapse
-
#filter_option_keys ⇒ Object
readonly
Returns the value of attribute filter_option_keys.
-
#filter_options ⇒ Object
readonly
Returns the value of attribute filter_options.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #filter_option(name, options = {}) ⇒ Object
- #filter_options_ordered ⇒ Object
-
#initialize(name, label, options = {}, &block) ⇒ FilterScope
constructor
A new instance of FilterScope.
- #key ⇒ Object
- #omit_from_ui? ⇒ Boolean
- #params_key ⇒ Object
- #selected_option_for(params) ⇒ Object
Constructor Details
permalink #initialize(name, label, options = {}, &block) ⇒ FilterScope
Returns a new instance of FilterScope.
31 32 33 34 35 36 37 38 39 |
# File 'lib/search_scope.rb', line 31 def initialize(name, label, ={}, &block) label ||= name.to_s.titleize @name, @label = name, label @filter_options = HashWithIndifferentAccess.new @filter_option_keys = [] @omit_from_ui = true if .delete(:omit_from_ui) #eval the block so that filter options can be initialized. Should only have calls to filter_option instance_eval(&block) end |
Instance Attribute Details
permalink #filter_option_keys ⇒ Object (readonly)
Returns the value of attribute filter_option_keys.
30 31 32 |
# File 'lib/search_scope.rb', line 30 def filter_option_keys @filter_option_keys end |
permalink #filter_options ⇒ Object (readonly)
Returns the value of attribute filter_options.
30 31 32 |
# File 'lib/search_scope.rb', line 30 def @filter_options end |
permalink #label ⇒ Object (readonly)
Returns the value of attribute label.
30 31 32 |
# File 'lib/search_scope.rb', line 30 def label @label end |
permalink #name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/search_scope.rb', line 30 def name @name end |
Instance Method Details
permalink #filter_option(name, options = {}) ⇒ Object
[View source]
45 46 47 48 49 50 51 |
# File 'lib/search_scope.rb', line 45 def filter_option(name, ={}) name = name.to_s raise "Already defined a filter_option (#{name.inspect}) for filter_scope (#{self.name})}" if filter_option_keys.include? name @filter_options_ordered = nil filter_option_keys << name [name] = FilterScopeOption.new(name, [:value], [:label], [:scope]) end |
permalink #filter_options_ordered ⇒ Object
[View source]
53 54 55 56 57 58 59 60 |
# File 'lib/search_scope.rb', line 53 def return @filter_options_ordered if @filter_options_ordered @filter_options_ordered = [] filter_option_keys.each do |key| @filter_options_ordered << [key] end @filter_options_ordered end |
permalink #key ⇒ Object
[View source]
62 63 64 |
# File 'lib/search_scope.rb', line 62 def key @key ||= "filter_#{name}".intern end |
permalink #omit_from_ui? ⇒ Boolean
41 42 43 |
# File 'lib/search_scope.rb', line 41 def omit_from_ui? @omit_from_ui ? true : false end |
permalink #params_key ⇒ Object
[View source]
66 67 68 |
# File 'lib/search_scope.rb', line 66 def params_key @params_key ||= key.to_s end |
permalink #selected_option_for(params) ⇒ Object
[View source]
70 71 72 73 |
# File 'lib/search_scope.rb', line 70 def selected_option_for(params) selected_option_key = params[self.params_key] self.[selected_option_key] end |