class Filterameter::FilterDeclaration
Filter Declaration¶ ↑
Class FilterDeclaration
captures the filter declaration within the controller.
Constants
- VALID_RANGE_OPTIONS
Attributes
association[R]
name[R]
parameter_name[R]
validations[R]
Public Class Methods
new(parameter_name, options)
click to toggle source
# File lib/filterameter/filter_declaration.rb, line 15 def initialize(parameter_name, options) @parameter_name = parameter_name.to_s validate_options(options) @name = options.fetch(:name, parameter_name).to_s @association = options[:association] @filter_on_empty = options.fetch(:filter_on_empty, false) @validations = Array.wrap(options[:validates]) @raw_partial_options = options.fetch(:partial, false) @raw_range = options[:range] end
Public Instance Methods
filter_on_empty?()
click to toggle source
# File lib/filterameter/filter_declaration.rb, line 35 def filter_on_empty? @filter_on_empty end
maximum?()
click to toggle source
# File lib/filterameter/filter_declaration.rb, line 59 def maximum? @raw_range == :max_only end
minimum?()
click to toggle source
# File lib/filterameter/filter_declaration.rb, line 55 def minimum? @raw_range == :min_only end
nested?()
click to toggle source
# File lib/filterameter/filter_declaration.rb, line 27 def nested? @association.present? end
partial_options()
click to toggle source
# File lib/filterameter/filter_declaration.rb, line 43 def partial_options @partial_options ||= @raw_partial_options ? Options::PartialOptions.new(@raw_partial_options) : nil end
partial_search?()
click to toggle source
# File lib/filterameter/filter_declaration.rb, line 39 def partial_search? partial_options.present? end
range?()
click to toggle source
# File lib/filterameter/filter_declaration.rb, line 51 def range? @raw_range == true end
range_enabled?()
click to toggle source
# File lib/filterameter/filter_declaration.rb, line 47 def range_enabled? @raw_range.present? end
validations?()
click to toggle source
# File lib/filterameter/filter_declaration.rb, line 31 def validations? !@validations.empty? end
Private Instance Methods
validate_options(options)
click to toggle source
# File lib/filterameter/filter_declaration.rb, line 65 def validate_options(options) options.assert_valid_keys(:name, :association, :filter_on_empty, :validates, :partial, :range) validate_range(options[:range]) if options.key?(:range) end
validate_range(range)
click to toggle source
# File lib/filterameter/filter_declaration.rb, line 70 def validate_range(range) return if VALID_RANGE_OPTIONS.include?(range) raise ArgumentError, "Invalid range option: #{range}" end