class Apia::Definitions::Argument
Attributes
array[RW]
default[RW]
options[R]
required[RW]
type[W]
validations[R]
Public Class Methods
new(name, id: nil)
click to toggle source
# File lib/apia/definitions/argument.rb, line 18 def initialize(name, id: nil) @id = id @name = name @validations = [] end
Public Instance Methods
array?()
click to toggle source
Is this an array?
@return [Boolean]
# File lib/apia/definitions/argument.rb, line 60 def array? @array == true end
dsl()
click to toggle source
# File lib/apia/definitions/argument.rb, line 24 def dsl @dsl ||= DSLs::Argument.new(self) end
required?()
click to toggle source
Is this argument required?
@return [Boolean]
# File lib/apia/definitions/argument.rb, line 53 def required? @required == true end
type()
click to toggle source
Return the type of object (either a ArgumentSet
or a Scalar
) which this argument represents.
@return [Class]
# File lib/apia/definitions/argument.rb, line 46 def type Type.new(@type) end
validate(errors)
click to toggle source
# File lib/apia/definitions/argument.rb, line 28 def validate(errors) if @name.nil? errors.add self, 'MissingName', 'Arguments must have a name' elsif @name.to_s !~ /\A[a-z0-9\-_]+\z/i errors.add self, 'InvalidName', 'Argument name must only include letters, numbers, hyphens and underscores' end if @type.nil? errors.add self, 'MissingType', 'Arguments must have a type' elsif !type.usable_for_argument? errors.add self, 'InvalidType', 'Type must be an argument set, scalar or enum' end end
validate_value(value)
click to toggle source
Validate a given value through all validations and return an array of all errors
@param value [Object] @return [Array]
# File lib/apia/definitions/argument.rb, line 69 def validate_value(value) @validations.each_with_object([]) do |validation, errors| errors << validation[:name] unless validation[:block].call(value) end end