Class: RubyFly::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_fly/commands/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
# File 'lib/ruby_fly/commands/base.rb', line 8

def initialize(opts = {})
  @binary = opts[:binary] || RubyFly.configuration.binary
  @stdin = stdin || RubyFly.configuration.stdin
  @stdout = stdout || RubyFly.configuration.stdout
  @stderr = stderr || RubyFly.configuration.stderr
end

Instance Attribute Details

#binaryObject (readonly)

Returns the value of attribute binary.



6
7
8
# File 'lib/ruby_fly/commands/base.rb', line 6

def binary
  @binary
end

#stderrObject (readonly)

Returns the value of attribute stderr.



6
7
8
# File 'lib/ruby_fly/commands/base.rb', line 6

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



6
7
8
# File 'lib/ruby_fly/commands/base.rb', line 6

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



6
7
8
# File 'lib/ruby_fly/commands/base.rb', line 6

def stdout
  @stdout
end

Instance Method Details

#configure_command(builder, opts) ⇒ Object



43
44
45
# File 'lib/ruby_fly/commands/base.rb', line 43

def configure_command(builder, opts)
  builder
end

#do_after(opts) ⇒ Object



47
48
# File 'lib/ruby_fly/commands/base.rb', line 47

def do_after(opts)
end

#do_around(opts, &block) ⇒ Object



39
40
41
# File 'lib/ruby_fly/commands/base.rb', line 39

def do_around(opts, &block)
  block.call(opts)
end

#do_before(opts) ⇒ Object



36
37
# File 'lib/ruby_fly/commands/base.rb', line 36

def do_before(opts)
end

#execute(opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_fly/commands/base.rb', line 15

def execute(opts = {})
  builder = instantiate_builder

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

#instantiate_builderObject



30
31
32
33
34
# File 'lib/ruby_fly/commands/base.rb', line 30

def instantiate_builder
  Lino::CommandLineBuilder
      .for_command(binary)
      .with_option_separator('=')
end