class ActiveScaffold::DataStructures::Filter
Attributes
Public Class Methods
Source
# 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 @options = [] @weight = 0 end
Public Instance Methods
Source
# File lib/active_scaffold/data_structures/filter.rb, line 42 def [](option_name) @options.find { |option| option.name.to_s == option_name.to_s } end
finds a FilterOption
by matching the name
Source
# File lib/active_scaffold/data_structures/filter.rb, line 19 def add(name, options = {}) 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, options) @default_option ||= option.name @options << option self end
adds a FilterOption
, creating one from the arguments if need be
Also aliased as: <<
Source
# File lib/active_scaffold/data_structures/filter.rb, line 34 def default_option=(name) option = self[name] raise ArgumentError, "'#{name}' option not found" unless option @default_option = option.name end
Source
# File lib/active_scaffold/data_structures/filter.rb, line 46 def delete(option_name) @options.delete self[option_name] end
Source
# 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
Source
# File lib/active_scaffold/data_structures/filter.rb, line 51 def each(&) @options.each(&) end
iterates over the links, possibly by type
Source
# File lib/active_scaffold/data_structures/filter.rb, line 55 def empty? @options.empty? end
Source
# 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
Protected Instance Methods
Source
# File lib/active_scaffold/data_structures/filter.rb, line 80 def initialize_copy(from) @options = [] from.each { |option| @options << option.clone } end
called during clone or dup. makes the clone/dup deeper.