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,

   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,

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

   second: :not_yet_implemented,

   time: :not_yet_implemented,

   uppercase_string: :not_yet_implemented,

   year: :year
}
VERSION =
"0.1.2"
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



55
56
57
# File 'lib/lab42/basic_constraints.rb', line 55

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

Instance Method Details

#all_constraintsObject



39
40
41
# File 'lib/lab42/basic_constraints.rb', line 39

def all_constraints
  Constraints.keys
end

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



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/lab42/basic_constraints.rb', line 43

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)
  end
end