Completed
Push — master ( 8c5aaa...f46502 )
by Michael
01:05
created

RackThor   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 25
ccs 15
cts 15
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 21 1
1 1
require 'hanami/router'
2 1
require 'stringio'
3
4 1
class RackThor
5 1
  attr_reader :router
6
7 1
  def initialize(cli)
8 2
    @cli = cli
9 2
    @router = Hanami::Router.new
10 2
    cli.all_commands.each do |name, c|
11 6
      @router.post "/#{name}", to: ->(env) do
12 2
        req = Rack::Request.new(env)
13 2
        begin
14 2
          $stdout = StringIO.new
15 2
          command = @cli.all_commands[name]
16
          @cli.new([], req.params['options'] || {}, {
17
            current_command: command,
18
            command_options: command.options
19 2
          }).invoke(name, req.params['args'] || [])
20 2
          $stdout.close
21 2
          [200, {}, [$stdout.string]]
22
        ensure
23 2
          $stdout = STDOUT
24
        end
25
      end
26
    end
27
  end
28
end
29