Translation table
This page contains a table of demonstrative translations of step definitions into result invocations.
It is especially useful for newcomers that are not familiar with the Convenient Service DSL yet.
Any combination of the in
and out
argument types described throughout this reference can be used together.
No in
or out
Definition:
step AssertNodeAvailable
Translation:
def step_result
@step_result ||= AssertNodeAvailable.result
end
One in
usual method
Definitions (equivalent):
step ValidateUncastedParams,
in: :params
step ValidateUncastedParams,
in: [
:params
]
Translation:
def step_result
@step_result ||=
ValidateUncastedParams.result(
params: params
)
end
Multiple in
usual methods
Definition:
step LogRequestParams,
in: [
:request,
:params
]
Translation:
def step_result
@step_result ||=
LogRequestParams.result(
request: request,
params: params
)
end
One in
alias method
Definitions (equivalent):
step ValidateCastedParams,
in: {casted_params: :params}
step ValidateCastedParams,
in: [
{casted_params: :params}
]
Translation:
def step_result
@step_result ||=
ValidateCastedParams.result(
casted_params: params
)
end
Multiple in
alias method
Definitions:
step AuditContent,
in: [
{content: :content_without_comments},
{verbose: :debug}
]
Translation:
def step_result
@step_result ||=
AuditContent.result(
content: content_without_comments,
verbose: debug
)
end
One out
usual method
Definitions (equivalent):
step ReadFileContent,
in: :path,
out: :content
step ReadFileContent,
in: :path,
out: [
:content
]
Translation:
def step_result
@step_result ||=
ReadFileContent.result(
path: path
)
end
def content
step_result.data[:content]
end
Multiple out
usual methods
Definition:
step CastParams,
in: :params,
out: [
:original_params,
:casted_params
]
Translation:
def step_result
@step_result ||=
CastParams.result(
params: params
)
end
def original_params
step_result.data[:original_params]
end
def casted_params
step_result.data[:casted_params]
end
One out
alias method
Definitions (equivalent):
step FormatHeader,
in: :parsed_content,
out: {formatted_content: :formatted_header_content}
step FormatHeader,
in: :parsed_content,
out: [
{formatted_content: :formatted_header_content}
]
Translation:
def step_result
@step_result ||=
FormatHeader.result(
parsed_content: parsed_content
)
end
def formatted_header_content
step_result.data[:formatted_content]
end
Multiple out
alias methods
Definition:
step ExtractParamsFromRequest,
in: :request,
out: [
{header_params: :request_params_from_header},
{body_params: :request_params_from_body}
]
Translation:
def step_result
@step_result ||=
ExtractParamsFromRequest.result(
request: request
)
end
def request_params_from_header
step_result.data[:header_params]
end
def request_params_from_body
step_result.data[:body_params]
end
One in
raw value
Definitions (equivalent):
step AssertFeatureEnabled,
in: {name: raw(:chat_v2)}
step AssertFeatureEnabled,
in: [
{name: raw(:chat_v2)}
]
Translation:
def step_result
@step_result ||=
AssertFeatureEnabled.result(
name: :chat_v2
)
end
Multiple in
raw values
Definitions (equivalent):
step PrintShellCommand,
in: [
{text: raw("ls -a")}
{stream: raw($stdout)}
]
Translation:
def step_result
@step_result ||=
PrintShellCommand.result(
text: "ls -a",
stream: $stdout
)
end
in
raw values are useful for passing values, constants, methods, etc from the class scope.
step PrintShellCommand,
in: [
{text: raw(display_directory_structure_command)}
{stream: raw($stdout)}
]
def self.display_directory_structure_command
"ls -a"
end
One in
proc method
Definitions (equivalent):
step RemoveDirectoryRecursively,
in: {path: ->{ "/tmp" }}
step RemoveDirectoryRecursively,
in: [
{path: ->{ "/tmp" }}
]
Translation:
def step_result
@step_result ||=
RemoveDirectoryRecursively.result(
path: "/tmp"
)
end
Multiple in
proc methods
Definition:
step CreateSoftLink,
in: [
{source: ->{ "~/.bash_profile" }},
{destination: ->{ "#{Dir.pwd}/bash_profile_link" }}
]
Translation:
def step_result
@step_result ||=
CreateSoftLink.result(
source: "~/.bash_profile",
destination: "#{Dir.pwd}/bash_profile_link"
)
end
in
proc methods are useful for passing values, constants, methods, etc from the instance scope.
step CreateSoftLink,
in: [
{source: ->{ "~/.bash_profile" }},
{destination: ->{ generate_destination_path }}
]
def generate_destination_path
"#{Dir.pwd}/bash_profile_link"
end
All-in-one example:
Definition:
ENV["API_ONLY"] = true
class UpdatePost
include ConvenientService::Standard::Config
PERMITTED_PARAMS = [:id, :format, :title, :description, :tags, :sources]
attr_reader :http_string
# ...
step PrepareRequestObject
in: [
:http_string,
{url_pattern: raw(url_pattern)},
{role: ->{ admin? }},
{permitted_keys: raw(PERMITTED_PARAMS)}
{defaults: ->{ resolve_defaults_values }}
],
out: [
:params_from_path,
:params_from_body,
{headers: :request_headers}
]
# ...
def self.url_pattern
/^\/rules\/(?<id>\d+)\.(?<format>\w+)$/
end
def admin?
false
end
def resolve_defaults_values
defaults_values = {format: "html", tags: [], sources: []}
defaults_values[:format] = "json" if ENV["API_ONLY"]
defaults_values
end
# ...
end
Translation:
ENV["API_ONLY"] = true
class UpdatePost
include ConvenientService::Standard::Config
PERMITTED_PARAMS = [:id, :format, :title, :description, :tags, :sources]
attr_reader :http_string
# ...
def step_result
@step_result ||= PrepareRequestObject.result(
http_string: http_string,
url_pattern: /^\/rules\/(?<id>\d+)\.(?<format>\w+)$/,
role: admin?, # => false
permitted_keys: [:id, :format, :title, :description, :tags, :sources],
defaults: resolve_defaults_values # => {format: "json", tags: [], sources: []}
)
end
def params_from_path
step_result.data[:params_from_path]
end
def params_from_body
step_result.data[:params_from_body]
end
def request_headers
step_result.data[:headers]
end
# ...
def self.url_pattern
/^\/rules\/(?<id>\d+)\.(?<format>\w+)$/
end
def admin?
false
end
def resolve_defaults_values
defaults_values = {format: "html", tags: [], sources: []}
defaults_values[:format] = "json" if ENV["API_ONLY"]
defaults_values
end
# ...
end
def step_result
is used to express the concept.
In reality, such a method is not generated by the Convenient Service under the hood.
It utilizes a lower-level toolset that is out of the scope of this guide.