Module: PUNK::Plugins::Validation::InstanceMethods
- Included in:
- Validatable
- Defined in:
- lib/punk/framework/plugins/validation.rb
Instance Method Summary collapse
- #validates_email(atts, opts = {}) ⇒ Object
- #validates_event(name, event) ⇒ Object
- #validates_phone(atts, opts = {}) ⇒ Object
- #validates_state(name, state) ⇒ Object
- #validates_url(atts, opts = {}) ⇒ Object
Instance Method Details
#validates_email(atts, opts = {}) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/punk/framework/plugins/validation.rb', line 17 def validates_email(atts, opts = {}) default = {message: "is not an email address"} validatable_attributes(atts, default.merge(opts)) do |_name, value, | unless URI::MailTo::EMAIL_REGEXP.match(value) end end |
#validates_event(name, event) ⇒ Object
35 36 37 |
# File 'lib/punk/framework/plugins/validation.rb', line 35 def validates_event(name, event) errors.add(name, "may not #{event}") unless self[name].send("may_#{event}?") end |
#validates_phone(atts, opts = {}) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/punk/framework/plugins/validation.rb', line 24 def validates_phone(atts, opts = {}) default = {message: "is not a phone number"} validatable_attributes(atts, default.merge(opts)) do |_name, value, | unless Phony.plausible?(value) end end |
#validates_state(name, state) ⇒ Object
31 32 33 |
# File 'lib/punk/framework/plugins/validation.rb', line 31 def validates_state(name, state) errors.add(name, "is not in #{state} state") unless self[name].send("#{state}?") end |
#validates_url(atts, opts = {}) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/punk/framework/plugins/validation.rb', line 10 def validates_url(atts, opts = {}) default = {message: "is not a URL"} validatable_attributes(atts, default.merge(opts)) do |_name, value, | unless URI::DEFAULT_PARSER.make_regexp.match(value).to_a.compact.length > 2 end end |