Sha256: 8e4179ffddd842177736088a116074b7c3fb5a4d9c2341abb7558204feb16bf2
Contents?: true
Size: 1.22 KB
Versions: 3
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true module Grumlin module StepsSerializers class String < Serializer # constructor params: apply_shortcuts: true|false, default: false # constructor params: anonymous: true|false, default: false # TODO: add pretty def serialize steps = @params[:apply_shortcuts] ? ShortcutsApplyer.call(@steps) : @steps configuration_steps = serialize_steps(steps.configuration_steps) regular_steps = serialize_steps(steps.steps) "#{prefix}.#{(configuration_steps + regular_steps).join(".")}" end private def prefix @prefix ||= @params[:anonymous] ? "__" : "g" end def serialize_arg(arg) return "\"#{arg}\"" if arg.is_a?(::String) || arg.is_a?(Symbol) return "#{arg.type}.#{arg.value}" if arg.is_a?(Grumlin::TypedValue) return arg.to_s if arg.is_a?(Grumlin::Expressions::WithOptions) return arg unless arg.is_a?(Steps) StepsSerializers::String.new(arg, anonymous: true, **@params).serialize end def serialize_steps(steps) steps.map do |step| "#{step.name}(#{step.arguments.map { |a| serialize_arg(a) }.join(", ")})" end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
grumlin-0.17.0 | lib/grumlin/steps_serializers/string.rb |
grumlin-0.16.1 | lib/grumlin/steps_serializers/string.rb |
grumlin-0.16.0 | lib/grumlin/steps_serializers/string.rb |