Sha256: ce4322e84de50d74299f9d91f8366b3426be98ae6ecb18a1245adb8fa5be177f
Contents?: true
Size: 1.35 KB
Versions: 14
Compression:
Stored size: 1.35 KB
Contents
# frozen_string_literal: true module Opera module Operation module Builder INSTRUCTIONS = %I[validate transaction benchmark step success finish_if operation operations].freeze def self.included(base) base.extend(ClassMethods) end module ClassMethods def instructions @instructions ||= [] end INSTRUCTIONS.each do |instruction| define_method instruction do |method = nil, &blk| instructions.concat(InnerBuilder.new.send(instruction, method, &blk)) end end end class InnerBuilder attr_reader :instructions def initialize(&block) @instructions = [] instance_eval(&block) if block_given? end INSTRUCTIONS.each do |instruction| define_method instruction do |method = nil, &blk| instructions << if !blk.nil? { kind: instruction, instructions: InnerBuilder.new(&blk).instructions } else { kind: instruction, method: method } end end end end end end end
Version data entries
14 entries across 14 versions & 1 rubygems