Skip to content

struct Athena::HTTPKernel::Controller::ParameterMetadata(T)
inherits Struct #

Represents a controller action parameter. Stores metadata associated with it, such as its name, type, and default value if any.

Methods#

#default_value : T#

Returns the default value for this parameter, raising an exception if it does not have one.

View source

#default_value? : T | ::Nil#

Returns the default value for this parameter, or nil if it does not have one.

View source

#first_type_of(klass : Type.class) forall Type#

Returns the metaclass of the first matching type variable that is an #instance_of? the provided klass, or nil if none match. If this the #type is union, this would be the first viable type.

AHK::Controller::ParameterMetadata(Int32).new("foo").first_type_of(Int32)                            # => Int32.class
AHK::Controller::ParameterMetadata(String | Int32 | Bool).new("foo").first_type_of(Int32)            # => Int32.class
AHK::Controller::ParameterMetadata(String | Int8 | Float64 | Int64).new("foo").first_type_of(Number) # => Float64.class
AHK::Controller::ParameterMetadata(String | Int32 | Bool).new("foo").first_type_of(Float64)          # => nil
View source

#has_default? : Bool#

Returns true if this parameter has a default value set, otherwise false.

View source

#inspect(io : IO) : Nil#

Appends this struct's name and instance variables names and values to the given IO.

struct Point
  def initialize(@x : Int32, @y : Int32)
  end
end

p1 = Point.new 1, 2
p1.to_s    # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"
View source

#instance_of?(klass : Type.class) : Bool forall Type#

Returns true if this parameter's #type includes the provided klass.

AHK::Controller::ParameterMetadata(Int32).new("foo").instance_of?(Int32)       # => true
AHK::Controller::ParameterMetadata(Int32 | Bool).new("foo").instance_of?(Bool) # => true
AHK::Controller::ParameterMetadata(Int32).new("foo").instance_of?(String)      # => false
View source

#name : String#

Returns the name of the parameter.

View source

#nilable? : Bool#

If nil is a valid value for the parameter.

View source

#type : T.class#

The type of the parameter, i.e. what its type restriction is.

View source