Sha256: 402474570d210fc3f4e874ca999fb9164e9dfd21deb11cd711cdc551b1551a3e

Contents?: true

Size: 1014 Bytes

Versions: 3

Compression:

Stored size: 1014 Bytes

Contents

require_relative "method_reflection"

class ::Simple::Service::Action::Parameter
  def self.reflect_on_method(service:, name:)
    reflected_parameters = ::Simple::Service::Action::MethodReflection.parameters(service, name)
    @parameters = reflected_parameters.map { |ary| new(*ary) }
  end

  def keyword?
    [:keyreq, :key].include? @kind
  end

  def positional?
    [:req, :opt].include? @kind
  end

  def required?
    [:req, :keyreq].include? @kind
  end

  def variadic?
    @kind == :rest
  end

  attr_reader :name
  attr_reader :kind

  # The parameter's default value (if any)
  attr_reader :default_value

  def initialize(kind, name, *default_value)
    # The parameter list matches the values returned from MethodReflection.parameters,
    # which has two or three entries: <tt>kind, name [ . default_value ]</tt>

    expect! kind => [:req, :opt, :keyreq, :key, :rest]
    expect! default_value.length => [0, 1]

    @kind = kind
    @name = name
    @default_value = default_value[0]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
simple-service-0.1.4 lib/simple/service/action/parameter.rb
simple-service-0.1.3 lib/simple/service/action/parameter.rb
simple-service-0.1.2 lib/simple/service/action/parameter.rb