Sha256: 36a11fd6eab17761706da260ae18306cfd774d4bb175b2fa01bd3c596ab613dd
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
require 'open3' module WIP module Runner module Shell module Handlers class Base def initialize(content, &block) @content = clean(content) @output = StringIO.new instance_exec(&block) if block_given? end def content(format = :text) case format when :markdown "```\n#{@content}\n```" else @content end end def execute(io, env, &block) raise NotImplementedError end def output @output.string end def type @type ||= self.class.name.split('::').last end protected def executable @executable ||= begin content = @content.gsub(/"/, '\"').gsub(/\$/, "\\$") %Q{bash -c "#{content}"} end end private def clean(string) return if string.nil? indent = (string.scan(/^[ \t]*(?=\S)/).min || '').size string.gsub(/^[ \t]{#{indent}}/, '').strip end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wip-runner-0.4.1 | lib/wip/runner/shell/handlers/base.rb |