Sha256: ecc1a3ee7de47fc1bba205c31c11302adba3f65f48eab4d98768f77ae046f8da

Contents?: true

Size: 1.19 KB

Versions: 20

Compression:

Stored size: 1.19 KB

Contents

require 'lino'

require_relative './result'

module RubyGPG2
  module Commands
    class Base
      def initialize(binary: nil, stdin: nil, stdout: nil, stderr: nil)
        @binary = binary || RubyGPG2.configuration.binary
        @stdin = stdin || RubyGPG2.configuration.stdin
        @stdout = stdout || RubyGPG2.configuration.stdout
        @stderr = stderr || RubyGPG2.configuration.stderr
      end

      def execute(opts = {})
        builder = instantiate_builder

        do_before(opts)
        do_around(opts) do |updated_opts|
          builder = configure_command(builder, updated_opts)
          builder
              .build
              .execute(
                  stdin: stdin,
                  stdout: stdout,
                  stderr: stderr)
        end
        do_after(opts)
      end

      protected

      attr_reader :binary, :stdin, :stdout, :stderr

      def instantiate_builder
        Lino::CommandLineBuilder
            .for_command(binary)
      end

      def do_before(opts)
      end

      def configure_command(builder, opts)
        builder
      end

      def do_around(opts)
        yield opts
      end

      def do_after(opts)
        Result.new
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ruby_gpg2-0.9.0.pre.6 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.9.0.pre.5 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.9.0.pre.4 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.9.0.pre.3 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.9.0.pre.2 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.9.0.pre.1 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.8.0 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.7.0.pre.1 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.6.0 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.5.0.pre.1 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.4.0 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.3.0.pre.2 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.3.0.pre.1 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.2.0 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.1.0.pre.27 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.1.0.pre.26 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.1.0.pre.25 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.1.0.pre.24 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.1.0.pre.23 lib/ruby_gpg2/commands/base.rb
ruby_gpg2-0.1.0.pre.22 lib/ruby_gpg2/commands/base.rb