Module: Redirector::RegexAttribute
- Included in:
- RedirectRule, RequestEnvironmentRule
- Defined in:
- lib/redirector/regex_attribute.rb
Defined Under Namespace
Modules: ValidationMethod
Instance Method Summary collapse
Instance Method Details
#regex_attribute(attribute_name) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/redirector/regex_attribute.rb', line 4 def regex_attribute(attribute_name) include ValidationMethod cattr_accessor :regex_attribute_name self.regex_attribute_name = attribute_name validates "#{attribute_name}_is_regex".to_sym, :inclusion => { :in => ['0', '1', true, false] } validates "#{attribute_name}_is_case_sensitive".to_sym, :inclusion => { :in => ['0', '1', true, false] } validate :regex_attribute_is_valid_regex define_method("#{regex_attribute_name}_regex") do if self.send("#{regex_attribute_name}_is_case_sensitive?") Regexp.compile(self.send(regex_attribute_name)) else Regexp.compile(self.send(regex_attribute_name), Regexp::IGNORECASE) end end end |