Module: Parameters::Types Private

Defined in:
lib/parameters/types/types.rb,
lib/parameters/types/set.rb,
lib/parameters/types/uri.rb,
lib/parameters/types/date.rb,
lib/parameters/types/hash.rb,
lib/parameters/types/proc.rb,
lib/parameters/types/time.rb,
lib/parameters/types/type.rb,
lib/parameters/types/array.rb,
lib/parameters/types/class.rb,
lib/parameters/types/float.rb,
lib/parameters/types/object.rb,
lib/parameters/types/regexp.rb,
lib/parameters/types/string.rb,
lib/parameters/types/symbol.rb,
lib/parameters/types/boolean.rb,
lib/parameters/types/integer.rb,
lib/parameters/types/date_time.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Since:

  • 0.3.0

Defined Under Namespace

Classes: Array, Boolean, Class, Date, DateTime, Float, Hash, Integer, Object, Proc, Regexp, Set, String, Symbol, Time, Type, URI

Class Method Summary collapse

Class Method Details

.[](type) ⇒ Types::Type

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Maps a Hash, Set, Array, Proc or Class to a Type.

Parameters:

Returns:

Raises:

  • (TypeError)

    The Ruby Type could not be mapped to a Parameter Type.

Since:

  • 0.3.0



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/parameters/types/types.rb', line 63

def self.[](type)
  case type
  when ::Hash
    key_type, value_type = type.entries[0]

    Hash.new(self[key_type],self[value_type])
  when ::Set
    Set.new(self[type.entries[0]])
  when ::Array
    Array.new(self[type[0]])
  when ::Proc
    Proc.new(type)
  when true
    Boolean
  when nil
    Object
  when ::Class
    if type_defined?(type.name)
      type_get(type.name)
    else
      Class.new(type)
    end
  when ::Module
    if type_defined?(type.name)
      type_get(type.name)
    else
      raise(TypeError,"unknown parameter type: #{type.inspect}")
    end
  else
    raise(TypeError,"invalid parameter type: #{type.inspect}")
  end
end

.type_defined?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determines if a Type is defined.

Parameters:

Returns:

Since:

  • 0.3.0



25
26
27
# File 'lib/parameters/types/types.rb', line 25

def self.type_defined?(name)
  const_defined?(name) && (const_get(name) < Type)
end

.type_get(name) ⇒ Type

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Looks up a Type.

Parameters:

Returns:

Raises:

  • (NameError)

    The type could not be found.

Since:

  • 0.3.0



41
42
43
44
45
46
47
48
49
# File 'lib/parameters/types/types.rb', line 41

def self.type_get(name)
  type = const_get(name)

  unless type < Type
    raise(NameError,"unknown Parameter Type: #{name}")
  end

  return type
end