module Definition::Dsl::Comparators
Public Instance Methods
Empty()
click to toggle source
Example: Empty
# File lib/definition/dsl/comparators.rb, line 80 def Empty # rubocop:disable Style/MethodName Types::Lambda.new(:empty) do |value| case value when String, Array, Hash conform_with(value) if value.empty? else value end end end
Equal(expected_value)
click to toggle source
Example: Equal(“value”)
# File lib/definition/dsl/comparators.rb, line 72 def Equal(expected_value) # rubocop:disable Style/MethodName Types::Lambda.new(:equal, context: { expected_value: expected_value }) do |value| conform_with(value) if value == expected_value end end
GreaterThen(min_value)
click to toggle source
Example: GreaterThen(5)
# File lib/definition/dsl/comparators.rb, line 40 def GreaterThen(min_value) # rubocop:disable Style/MethodName Types::Lambda.new("greater_then", context: { min_value: min_value }) do |value| conform_with(value) if value.is_a?(Numeric) && value > min_value end end
GreaterThenEqual(min_value)
click to toggle source
Example: GreaterThenEqual(5)
# File lib/definition/dsl/comparators.rb, line 48 def GreaterThenEqual(min_value) # rubocop:disable Style/MethodName Types::Lambda.new("greater_then_equal", context: { min_value: min_value }) do |value| conform_with(value) if value.is_a?(Numeric) && value >= min_value end end
LessThen(max_value)
click to toggle source
Example: LessThen(5)
# File lib/definition/dsl/comparators.rb, line 56 def LessThen(max_value) # rubocop:disable Style/MethodName Types::Lambda.new("less_then", context: { max_value: max_value }) do |value| conform_with(value) if value.is_a?(Numeric) && value < max_value end end
LessThenEqual(max_value)
click to toggle source
Example: LessThenEqual(5)
# File lib/definition/dsl/comparators.rb, line 64 def LessThenEqual(max_value) # rubocop:disable Style/MethodName Types::Lambda.new("less_then_equal", context: { max_value: max_value }) do |value| conform_with(value) if value.is_a?(Numeric) && value <= max_value end end
MaxSize(max_size)
click to toggle source
Example: MaxSize(5)
# File lib/definition/dsl/comparators.rb, line 8 def MaxSize(max_size) # rubocop:disable Style/MethodName Types::Lambda.new(:max_size, context: { max_size: max_size }) do |value| case value when String, Enumerable conform_with(value) if value.size <= max_size else value end end end
MinSize(min_size)
click to toggle source
Example: MinSize(5)
# File lib/definition/dsl/comparators.rb, line 21 def MinSize(min_size) # rubocop:disable Style/MethodName Types::Lambda.new(:min_size, context: { min_size: min_size }) do |value| case value when String, Enumerable conform_with(value) if value.size >= min_size else value end end end
NonEmpty()
click to toggle source
Example: NonEmpty
# File lib/definition/dsl/comparators.rb, line 93 def NonEmpty # rubocop:disable Style/MethodName Types::Lambda.new(:non_empty) do |value| case value when String, Array, Hash conform_with(value) unless value.empty? else value end end end
NonEmptyString()
click to toggle source
Example: NonEmptyString
# File lib/definition/dsl/comparators.rb, line 34 def NonEmptyString # rubocop:disable Style/MethodName Types::And.new(:non_empty_string, Type(String), MinSize(1)) end
Regex(regex, name: :regex)
click to toggle source
Example: Regex
# File lib/definition/dsl/comparators.rb, line 106 def Regex(regex, name: :regex) # rubocop:disable Style/MethodName Types::Lambda.new(name, context: { regex: regex.inspect }) do |value| case value when String conform_with(value) unless regex.match(value).nil? else value end end end