Class: Lafcadio::EmailField

Inherits:
StringField show all
Defined in:
lib/lafcadio/objectField.rb

Overview

EmailField takes a text value that is expected to be formatted as a single valid email address.

Instance Attribute Summary

Attributes inherited from ObjectField

#db_field_name, #domain_class, #mock_value, #name, #not_nil

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StringField

#value_for_sql

Methods inherited from ObjectField

#<=>, #bind_write?, create_from_xml, create_with_args, creation_parameters, #db_column, #db_will_automatically_write?, #default_mock_value, #prev_value, #process_before_verify, #value_for_sql, #value_from_sql, value_type, #verify

Constructor Details

#initialize(domain_class, name = "email") ⇒ EmailField

Returns a new instance of EmailField.



404
405
406
# File 'lib/lafcadio/objectField.rb', line 404

def initialize( domain_class, name = "email" )
	super( domain_class, name )
end

Class Method Details

.mock_valueObject

:nodoc:



304
305
306
# File 'lib/lafcadio/test.rb', line 304

def EmailField.mock_value #:nodoc:
	'[email protected]'
end

.valid_address(address) ⇒ Object

Is address a valid email address?



400
401
402
# File 'lib/lafcadio/objectField.rb', line 400

def self.valid_address(address)
	address =~ /^[^ @]+@[^ \.]+\.[^ ,]+$/
end

Instance Method Details

#verify_non_nil_value(value, pk_id) ⇒ Object

:nodoc:



408
409
410
411
412
413
414
415
416
417
# File 'lib/lafcadio/objectField.rb', line 408

def verify_non_nil_value(value, pk_id) #:nodoc:
	super(value, pk_id)
	if !EmailField.valid_address(value)
		raise(
			FieldValueError,
		  "#{ domain_class.name }##{ name } needs a valid email address.",
		  caller
		)
	end
end