Sha256: 29bc6dc15a44274fec2b45f8f8e899624a2661816a015fed8b99bcb3f51f6d8f

Contents?: true

Size: 1019 Bytes

Versions: 8

Compression:

Stored size: 1019 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.to_s
    @default_value = default_value[0]
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
simple-service-0.3.1 lib/simple/service/action/parameter.rb
simple-service-0.2.3 lib/simple/service/action/parameter.rb
simple-service-0.3.0 lib/simple/service/action/parameter.rb
simple-service-0.2.2 lib/simple/service/action/parameter.rb
simple-service-0.2.1 lib/simple/service/action/parameter.rb
simple-service-0.2.0 lib/simple/service/action/parameter.rb
simple-service-0.1.6 lib/simple/service/action/parameter.rb
simple-service-0.1.5 lib/simple/service/action/parameter.rb