Class: Apiwork::Introspection::Param::String

Inherits:
Base
  • Object
show all
Defined in:
lib/apiwork/introspection/param/string.rb

Overview

String param representing text values.

Examples:

Basic usage

param.type # => :string
param.scalar? # => true
param.string? # => true

Constraints

param.min # => 1 or nil
param.max # => 255 or nil
param.format # => :email or nil
param.boundable? # => true
param.formattable? # => true

Enum

if param.enum?
  param.enum # => ["draft", "published"]
  param.enum_reference? # => false
end

Instance Method Summary collapse

Methods inherited from Base

#array?, #binary?, #boolean?, #date?, #datetime?, #decimal?, #default?, #deprecated?, #description, #initialize, #integer?, #literal?, #nullable?, #number?, #numeric?, #object?, #optional?, #partial?, #record?, #reference?, #tag, #time?, #type, #union?, #unknown?, #uuid?

Constructor Details

This class inherits a constructor from Apiwork::Introspection::Param::Base

Instance Method Details

#boundable?Boolean

Whether this param is boundable.

Returns:



114
115
116
# File 'lib/apiwork/introspection/param/string.rb', line 114

def boundable?
  true
end

#concrete?Boolean

Whether this param is concrete.

Returns:



74
75
76
# File 'lib/apiwork/introspection/param/string.rb', line 74

def concrete?
  true
end

#defaultObject?

The default for this param.

Returns ‘nil` for both “no default” and “default is explicitly `nil`”. Use Base#default? to distinguish these cases.

Returns:



34
35
36
# File 'lib/apiwork/introspection/param/string.rb', line 34

def default
  @dump[:default]
end

#enumArray<String>, ...

The enum for this param.

Returns:



98
99
100
# File 'lib/apiwork/introspection/param/string.rb', line 98

def enum
  @dump[:enum]
end

#enum?Boolean

Whether this param has an enum.

Returns:



90
91
92
# File 'lib/apiwork/introspection/param/string.rb', line 90

def enum?
  @dump[:enum].present?
end

#enum_reference?Boolean

Whether this param is an enum reference.

Returns:



106
107
108
# File 'lib/apiwork/introspection/param/string.rb', line 106

def enum_reference?
  @dump[:enum].is_a?(Symbol)
end

#exampleObject?

The example for this param.

Returns:



42
43
44
# File 'lib/apiwork/introspection/param/string.rb', line 42

def example
  @dump[:example]
end

#formatSymbol?

The format for this param.

Returns:

  • (Symbol, nil)


50
51
52
# File 'lib/apiwork/introspection/param/string.rb', line 50

def format
  @dump[:format]
end

#formattable?Boolean

Whether this param is formattable.

Returns:



122
123
124
# File 'lib/apiwork/introspection/param/string.rb', line 122

def formattable?
  true
end

#maxInteger?

The maximum for this param.

Returns:



66
67
68
# File 'lib/apiwork/introspection/param/string.rb', line 66

def max
  @dump[:max]
end

#minInteger?

The minimum for this param.

Returns:



58
59
60
# File 'lib/apiwork/introspection/param/string.rb', line 58

def min
  @dump[:min]
end

#scalar?Boolean

Whether this param is scalar.

Returns:



82
83
84
# File 'lib/apiwork/introspection/param/string.rb', line 82

def scalar?
  true
end

#string?Boolean

Whether this param is a string.

Returns:



130
131
132
# File 'lib/apiwork/introspection/param/string.rb', line 130

def string?
  true
end

#to_hHash

Converts this param to a hash.

Returns:

  • (Hash)


138
139
140
141
142
143
144
145
146
147
# File 'lib/apiwork/introspection/param/string.rb', line 138

def to_h
  result = super
  result[:default] = default
  result[:enum] = enum if enum?
  result[:example] = example
  result[:format] = format
  result[:max] = max
  result[:min] = min
  result
end