Class: Simple::Service::Action::Parameter
- Inherits:
-
Object
- Object
- Simple::Service::Action::Parameter
- Defined in:
- lib/simple/service/action/parameter.rb
Instance Attribute Summary collapse
-
#default_value ⇒ Object
readonly
The parameter's default value (if any).
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(kind, name, *default_value) ⇒ Parameter
constructor
A new instance of Parameter.
- #keyword? ⇒ Boolean
- #positional? ⇒ Boolean
- #required? ⇒ Boolean
- #variadic? ⇒ Boolean
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_value ⇒ Object (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 |
#kind ⇒ Object (readonly)
Returns the value of attribute kind
26 27 28 |
# File 'lib/simple/service/action/parameter.rb', line 26 def kind @kind end |
#name ⇒ Object (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
9 10 11 |
# File 'lib/simple/service/action/parameter.rb', line 9 def keyword? [:keyreq, :key].include? @kind end |
#positional? ⇒ Boolean
13 14 15 |
# File 'lib/simple/service/action/parameter.rb', line 13 def positional? [:req, :opt].include? @kind end |
#required? ⇒ Boolean
17 18 19 |
# File 'lib/simple/service/action/parameter.rb', line 17 def required? [:req, :keyreq].include? @kind end |
#variadic? ⇒ Boolean
21 22 23 |
# File 'lib/simple/service/action/parameter.rb', line 21 def variadic? @kind == :rest end |