Class: Workflow::Callbacks::TransitionCallback::MethodArgumentBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/workflow/callbacks/transition_callback.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Builds arguments appropriate for calling the wrapped proc or method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transition_context, method) ⇒ MethodArgumentBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MethodArgumentBuilder.



50
51
52
53
54
55
# File 'lib/workflow/callbacks/transition_callback.rb', line 50

def initialize(transition_context, method)
  @transition_context = transition_context
  @method = method
  @from, @to, @event, @event_args, @attributes = transition_context.values
  build_args
end

Instance Attribute Details

#argsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
# File 'lib/workflow/callbacks/transition_callback.rb', line 49

def args
  @args
end

#attributesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/workflow/callbacks/transition_callback.rb', line 48

def attributes
  @attributes
end

#eventObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/workflow/callbacks/transition_callback.rb', line 48

def event
  @event
end

#event_argsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/workflow/callbacks/transition_callback.rb', line 48

def event_args
  @event_args
end

#fromObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/workflow/callbacks/transition_callback.rb', line 48

def from
  @from
end

#methodObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/workflow/callbacks/transition_callback.rb', line 48

def method
  @method
end

#toObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/workflow/callbacks/transition_callback.rb', line 48

def to
  @to
end

#transition_contextObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/workflow/callbacks/transition_callback.rb', line 48

def transition_context
  @transition_context
end

Instance Method Details

#build_argsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
60
61
# File 'lib/workflow/callbacks/transition_callback.rb', line 57

def build_args
  @args = name_arguments + rest_arguments
  kwargs = keyword_arguments.merge(keyrest_arguments)
  @args << kwargs unless kwargs.empty?
end

#keyrest_argumentsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



88
89
90
91
92
93
94
# File 'lib/workflow/callbacks/transition_callback.rb', line 88

def keyrest_arguments
  if keyrest_param
    attributes
  else
    {}
  end
end

#keyrest_paramObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



104
105
106
# File 'lib/workflow/callbacks/transition_callback.rb', line 104

def keyrest_param
  params_by_type(:keyrest).first
end

#keyword_argumentsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



82
83
84
85
86
# File 'lib/workflow/callbacks/transition_callback.rb', line 82

def keyword_arguments
  kw_params.map do |name|
    [name, attributes.delete(name)]
  end.to_h
end

#kw_paramsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/workflow/callbacks/transition_callback.rb', line 100

def kw_params
  params_by_type :keyreq, :keyopt
end

#name_argumentsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



63
64
65
66
67
68
69
70
71
72
# File 'lib/workflow/callbacks/transition_callback.rb', line 63

def name_arguments
  name_params.map do |name|
    case name
    when :to then to
    when :from then from
    when :event then event
    else (attributes.delete(name) || event_args.shift)
    end
  end
end

#name_paramsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



96
97
98
# File 'lib/workflow/callbacks/transition_callback.rb', line 96

def name_params
  params_by_type :opt, :req
end

#parametersArray

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameter definition for the object. See UnboundMethod#parameters

Returns:

  • (Array)

    Parameters



121
122
123
# File 'lib/workflow/callbacks/transition_callback.rb', line 121

def parameters
  method.parameters
end

#params_by_type(*types) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



112
113
114
115
116
# File 'lib/workflow/callbacks/transition_callback.rb', line 112

def params_by_type(*types)
  parameters.select do |type, _name|
    types.include? type
  end.map(&:last)
end

#rest_argumentsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



74
75
76
77
78
79
80
# File 'lib/workflow/callbacks/transition_callback.rb', line 74

def rest_arguments
  if rest_param
    event_args
  else
    []
  end
end

#rest_paramObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



108
109
110
# File 'lib/workflow/callbacks/transition_callback.rb', line 108

def rest_param
  params_by_type(:rest).first
end