Class: FluentValidation::RuleBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent_validation/rule_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute_rule) ⇒ RuleBuilder

Returns a new instance of RuleBuilder.



16
17
18
# File 'lib/fluent_validation/rule_builder.rb', line 16

def initialize(attribute_rule)
  @attribute_rule = attribute_rule
end

Instance Method Details

#email_addressObject



44
45
46
47
48
# File 'lib/fluent_validation/rule_builder.rb', line 44

def email_address
  validator = Validators::EmailValidator.new
  @attribute_rule.add_validator validator
  self
end

#exact_length(length) ⇒ Object



38
39
40
41
42
# File 'lib/fluent_validation/rule_builder.rb', line 38

def exact_length(length)
  validator = Validators::ExactLengthValidator.new(length)
  @attribute_rule.add_validator validator
  self
end

#greater_than(comparison_value) ⇒ Object



62
63
64
65
66
# File 'lib/fluent_validation/rule_builder.rb', line 62

def greater_than(comparison_value)
  validator = Validators::GreaterThanValidator.new(comparison_value)
  @attribute_rule.add_validator validator
  self
end

#greater_than_or_equal(comparison_value) ⇒ Object



68
69
70
71
72
# File 'lib/fluent_validation/rule_builder.rb', line 68

def greater_than_or_equal(comparison_value)
  validator = Validators::GreaterThanOrEqualValidator.new(comparison_value)
  @attribute_rule.add_validator validator
  self
end

#length(min, max) ⇒ Object



32
33
34
35
36
# File 'lib/fluent_validation/rule_builder.rb', line 32

def length(min, max)
  validator = Validators::LengthValidator.new(min, max)
  @attribute_rule.add_validator validator
  self
end

#less_than(comparison_value) ⇒ Object



50
51
52
53
54
# File 'lib/fluent_validation/rule_builder.rb', line 50

def less_than(comparison_value)
  validator = Validators::LessThanValidator.new(comparison_value)
  @attribute_rule.add_validator validator
  self
end

#less_than_or_equal(comparison_value) ⇒ Object



56
57
58
59
60
# File 'lib/fluent_validation/rule_builder.rb', line 56

def less_than_or_equal(comparison_value)
  validator = Validators::LessThanOrEqualValidator.new(comparison_value)
  @attribute_rule.add_validator validator
  self
end

#matches(regexp) ⇒ Object



74
75
76
77
78
# File 'lib/fluent_validation/rule_builder.rb', line 74

def matches(regexp)
  validator = Validators::RegularExpressionValidator.new(regexp)
  @attribute_rule.add_validator validator
  self
end

#must(&expression) ⇒ Object



80
81
82
83
84
# File 'lib/fluent_validation/rule_builder.rb', line 80

def must(&expression)
  validator = Validators::PredicateValidator.new(expression)
  @attribute_rule.add_validator validator
  self
end

#not_emptyObject



26
27
28
29
30
# File 'lib/fluent_validation/rule_builder.rb', line 26

def not_empty
  validator = Validators::NotEmptyValidator.new
  @attribute_rule.add_validator validator
  self
end

#not_nilObject



20
21
22
23
24
# File 'lib/fluent_validation/rule_builder.rb', line 20

def not_nil
  validator = Validators::NotNilValidator.new
  @attribute_rule.add_validator validator
  self
end

#set_collection_validator(validator) ⇒ Object



86
87
88
89
90
# File 'lib/fluent_validation/rule_builder.rb', line 86

def set_collection_validator(validator)
  validator_adaptor = Validators::ChildCollectionValidatorAdaptor.new validator
  @attribute_rule.add_validator validator_adaptor
  self
end

#when(&expression) ⇒ Object



102
103
104
105
# File 'lib/fluent_validation/rule_builder.rb', line 102

def when(&expression)
  @attribute_rule.condition = expression
  self
end

#with_error_code(error_code) ⇒ Object



97
98
99
100
# File 'lib/fluent_validation/rule_builder.rb', line 97

def with_error_code(error_code)
  @attribute_rule.error_code = error_code
  self
end

#with_name(name) ⇒ Object



92
93
94
95
# File 'lib/fluent_validation/rule_builder.rb', line 92

def with_name(name)
  @attribute_rule.attribute_name = name
  self
end