class FriendlyRoutes::Params::BooleanParams
@attr [String] true value for matching true @attr [String] false value for matching false
Attributes
false[RW]
true[RW]
Public Class Methods
new(name, options, optional: true)
click to toggle source
Calls superclass method
FriendlyRoutes::Params::Base::new
# File lib/friendly_routes/params/boolean_params.rb, line 10 def initialize(name, options, optional: true) check_params(options) super(:boolean, name, optional) @true = options[:true] @false = options[:false] end
Public Instance Methods
allowed?(value)
click to toggle source
(see Base#allowed?
) @param [Boolean, String] value boolean, or “True”/“False” strings @return [Boolean]
# File lib/friendly_routes/params/boolean_params.rb, line 38 def allowed?(value) [true, false, 'true', 'false'].include? value end
compose(value)
click to toggle source
(see Base#compose
) @param [Boolean, String] value boolean, or “True”/“False” strings @return [String] request value
# File lib/friendly_routes/params/boolean_params.rb, line 31 def compose(value) value == true || value == 'true' ? @true : @false end
constraints()
click to toggle source
# File lib/friendly_routes/params/boolean_params.rb, line 17 def constraints Regexp.new "#{@true}|#{@false}" end
parse(value)
click to toggle source
(see Base#parse
) @param [String] value request value @return [Boolean]
# File lib/friendly_routes/params/boolean_params.rb, line 24 def parse(value) (value == @true).to_s end
Private Instance Methods
check_params(options)
click to toggle source
# File lib/friendly_routes/params/boolean_params.rb, line 44 def check_params(options) valid = options.is_a?(Hash) && options[:true] && options[:false] raise ArgumentError, 'True and false options is required' unless valid end