Class: DataMapper::Types::String

Inherits:
String show all
Includes:
Base
Defined in:
lib/data_mapper/types/string.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#errors, included, #valid?

Methods inherited from String

#blank?

Methods included from Support::String

#compress_lines, #ensure_ends_with, #ensure_starts_with, #ensure_wrapped_with, included, #margin, #t

Class Method Details

.lengthObject



11
12
13
# File 'lib/data_mapper/types/string.rb', line 11

def self.length
  length_validator
end

.length_validatorObject



19
20
21
22
# File 'lib/data_mapper/types/string.rb', line 19

def self.length_validator
  @length_validator ||
    @length_validator = Validations::NumberValidator.new
end

.match_validatorObject



24
25
26
# File 'lib/data_mapper/types/string.rb', line 24

def self.match_validator
  @match_validator || @match_validator = Validations::StringValidator.new
end

.matches(regexp) ⇒ Object



15
16
17
# File 'lib/data_mapper/types/string.rb', line 15

def self.matches(regexp)
  match_validator.matches(regexp)
end

Instance Method Details

#do_validationsObject



28
29
30
31
# File 'lib/data_mapper/types/string.rb', line 28

def do_validations
  errors.concat(self.class.length_validator.errors_for(length))
  errors.concat(self.class.match_validator.errors_for(self))
end