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.



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

def initialize(attribute_rule)
  @attribute_rule = attribute_rule
end

Instance Method Details

#email_addressObject



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

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

#exact_length(length) ⇒ Object



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

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

#greater_than(comparison_value) ⇒ Object



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

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



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

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

#length(min, max) ⇒ Object



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

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

#less_than(comparison_value) ⇒ Object



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

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



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

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

#matches(regexp) ⇒ Object



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

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

#must(&expression) ⇒ Object



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

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

#not_nilObject



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

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

#set_collection_validator(validator) ⇒ Object



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

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

#when(&expression) ⇒ Object



90
91
92
93
# File 'lib/fluent_validation/rule_builder.rb', line 90

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

#with_name(name) ⇒ Object



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

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