Class: Simple::Service::Action::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/simple/service/action/parameter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, name, *default_value) ⇒ Parameter

Returns a new instance of Parameter



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/simple/service/action/parameter.rb', line 31

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

Instance Attribute Details

#default_valueObject (readonly)

The parameter's default value (if any)



29
30
31
# File 'lib/simple/service/action/parameter.rb', line 29

def default_value
  @default_value
end

#kindObject (readonly)

Returns the value of attribute kind



26
27
28
# File 'lib/simple/service/action/parameter.rb', line 26

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name



25
26
27
# File 'lib/simple/service/action/parameter.rb', line 25

def name
  @name
end

Class Method Details

.reflect_on_method(service:, name:) ⇒ Object



4
5
6
7
# File 'lib/simple/service/action/parameter.rb', line 4

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

Instance Method Details

#keyword?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/simple/service/action/parameter.rb', line 9

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

#positional?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/simple/service/action/parameter.rb', line 13

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

#required?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/simple/service/action/parameter.rb', line 17

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

#variadic?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/simple/service/action/parameter.rb', line 21

def variadic?
  @kind == :rest
end