Class: ActiveScaffold::DataStructures::Filter
- Includes:
- Enumerable
- Defined in:
- lib/active_scaffold/data_structures/filter.rb
Instance Attribute Summary collapse
-
#css_class ⇒ Object
Returns the value of attribute css_class.
-
#default_option ⇒ Object
Returns the value of attribute default_option.
- #description ⇒ Object
- #label ⇒ Object
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#security_method ⇒ Object
Returns the value of attribute security_method.
-
#type ⇒ Object
Returns the value of attribute type.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
-
#[](option_name) ⇒ Object
finds a FilterOption by matching the name.
-
#add(name, options = {}) ⇒ Object
(also: #<<)
adds a FilterOption, creating one from the arguments if need be.
- #delete(option_name) ⇒ Object
-
#each ⇒ Object
iterates over the links, possibly by type.
- #empty? ⇒ Boolean
-
#initialize(name, type) ⇒ Filter
constructor
A new instance of Filter.
Constructor Details
#initialize(name, type) ⇒ Filter
Returns a new instance of Filter.
9 10 11 12 13 14 15 16 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 9 def initialize(name, type) raise ArgumentError, 'Filter name must use only word characters (a-zA-Z0-9_)' unless name.match?(/\A\w+\z/) @label = @name = name.to_sym @type = type = [] @weight = 0 end |
Instance Attribute Details
#css_class ⇒ Object
Returns the value of attribute css_class.
7 8 9 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 7 def css_class @css_class end |
#default_option ⇒ Object
Returns the value of attribute default_option.
5 6 7 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 5 def default_option @default_option end |
#description ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 68 def description case @description when Symbol ActiveScaffold::Registry.cache(:translations, @description) { as_(@description) } else @description end end |
#label ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 59 def label(*) case @label when Symbol ActiveScaffold::Registry.cache(:translations, @label) { as_(@label) } else @label end end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 5 def name @name end |
#security_method ⇒ Object
Returns the value of attribute security_method.
7 8 9 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 7 def security_method @security_method end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 7 def type @type end |
#weight ⇒ Object
Returns the value of attribute weight.
7 8 9 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 7 def weight @weight end |
Instance Method Details
#[](option_name) ⇒ Object
finds a FilterOption by matching the name
42 43 44 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 42 def [](option_name) .find { |option| option.name.to_s == option_name.to_s } end |
#add(name, options = {}) ⇒ Object Also known as: <<
adds a FilterOption, creating one from the arguments if need be
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 19 def add(name, = {}) if name.is_a?(ActiveScaffold::DataStructures::FilterOption) option = name name = option.name end existing = self[name] raise ArgumentError, "there is a filter option with '#{name}' name" if existing option ||= ActiveScaffold::DataStructures::FilterOption.new(@name, name, ) @default_option ||= option.name << option self end |
#delete(option_name) ⇒ Object
46 47 48 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 46 def delete(option_name) .delete self[option_name] end |
#each ⇒ Object
iterates over the links, possibly by type
51 52 53 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 51 def each(&) .each(&) end |
#empty? ⇒ Boolean
55 56 57 |
# File 'lib/active_scaffold/data_structures/filter.rb', line 55 def empty? .empty? end |