Module: ValidArray
- Defined in:
- lib/valid_array.rb,
lib/valid_array/functions.rb
Overview
Namespace ValidArray
Defined Under Namespace
Modules: Functions, TypedArray Classes: DontInsertException
Class Method Summary collapse
-
.extended(mod) ⇒ Object
Hook the extension process in order to include the necessary functions and do some basic sanity checks.
-
.TypedArray(*types_allowed) ⇒ Object
Provide a factory method.
Instance Method Summary collapse
-
#validate(element) ⇒ Object
Default validator.
Class Method Details
.extended(mod) ⇒ Object
Hook the extension process in order to include the necessary functions and do some basic sanity checks.
10 11 12 13 14 |
# File 'lib/valid_array.rb', line 10 def self.extended(mod) mod.module_exec(self::Functions) do |functions_module| include functions_module end end |
.TypedArray(*types_allowed) ⇒ Object
Provide a factory method. Takes any number of types to accept as arguments and returns a class that behaves as a type-enforced array.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/valid_array/typed_array.rb', line 65 def ValidArray::TypedArray(*types_allowed) klass = Class.new( Array ) klass.class_exec(types_allowed) do |types_allowed| extend ValidArray extend TypedArray restricted_types *types_allowed end klass end |
Instance Method Details
#validate(element) ⇒ Object
Default validator. Override this.
Translates the provided item to insert to the new item. Raise an exception to prevent insertion. DontInsertException will be handled and ignored, other exceptions will be propergated.
31 32 33 |
# File 'lib/valid_array.rb', line 31 def validate(element) raise NotImplementedError, "You must implement validate." end |