Module: Lab42::BasicConstraints

Extended by:
BasicConstraints
Included in:
BasicConstraints
Defined in:
lib/lab42/basic_constraints.rb,
lib/lab42/basic_constraints/version.rb,
lib/lab42/basic_constraints/constraint.rb,
lib/lab42/basic_constraints/implementation.rb

Defined Under Namespace

Modules: Implementation Classes: Constraint

Constant Summary collapse

Constraints =
{
   all_digits_string: :not_yet_implemented,
   alphanumeric_string: :not_yet_implemented,

   bool: ->(x){[false, true].include? x},

   date: :date,
   date_time: :not_yet_implemented,
   day: :not_yet_implemented,

   hour: :not_yet_implemented,

   int: Integer,

   lowercase_string: :not_yet_implemented,

   minute: :not_yet_implemented,
   month: :not_yet_implemented,

   non_empty_string: :not_yet_implemented,
   non_negative_float: :not_yet_implemented,
   non_negative_int: :non_negative_int,
   non_negative_number: :not_yet_implemented,
   number: :not_yet_implemented,

   positive_float: :not_yet_implemented,
   positive_int: :positive_int,
   positive_number: :positive_number,

   second: :not_yet_implemented,
   string: String,

   time: :not_yet_implemented,

   uppercase_string: :not_yet_implemented,

   year: :year
}
VERSION =
"0.1.5"
ConstraintError =
Class.new RuntimeError
MissingDefaultError =
Class.new RuntimeError

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwds) ⇒ Object



60
61
62
# File 'lib/lab42/basic_constraints.rb', line 60

def method_missing(name, *args, **kwds)
  from_symbol(name, *args, **kwds) {super}
end

Instance Method Details

#all_constraintsObject



42
43
44
# File 'lib/lab42/basic_constraints.rb', line 42

def all_constraints
  Constraints.keys
end

#from_symbol(name, *args, **kwds, &blk) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lab42/basic_constraints.rb', line 46

def from_symbol name, *args, **kwds, &blk
  cons = Constraints.fetch(name, &blk)
  case cons
  # when Constraint
  #   cons
  when Proc
    Constraint.new(name, &cons)
  when Symbol
    Implementation.send(cons, *args, **kwds)
  when Class
    Constraint.new(name){ cons === _1 }
  end
end