Module: RailsResponseDumper

Defined in:
lib/rails_response_dumper/runner.rb,
lib/rails_response_dumper/defined.rb,
lib/rails_response_dumper/colorize.rb,
lib/rails_response_dumper/dump_block.rb,
lib/rails_response_dumper/option_parser.rb

Defined Under Namespace

Classes: Defined, DumpBlock, Runner

Constant Summary collapse

COLORS =
{
  cyan: 36,
  green: 32,
  red: 31
}.freeze
COLORIZE =
$stdout.tty?

Class Method Summary collapse

Class Method Details

.colorize(text, color) ⇒ Object



20
21
22
# File 'lib/rails_response_dumper/colorize.rb', line 20

def self.colorize(text, color)
  "\e[#{COLORS[color]}m#{text}\e[0m"
end

.parse_options!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rails_response_dumper/option_parser.rb', line 6

def self.parse_options!
  options = { 'dumps-dir' => Rails.root.join('dumps') }

  OptionParser.new do |opts|
    opts.banner += ' [glob]'

    opts.separator ''
    opts.separator 'Filtering:'
    opts.separator 'Run for specific files or globs:'
    opts.separator '  rails-response-dumper path/to/a_dumper.rb'

    opts.separator ''
    opts.separator 'Options:'

    opts.on('--dumps-dir PATH', 'Output dumps to this directory.') do |v|
      options['dumps-dir'] = v
    end

    opts.on('--fail-fast', 'Abort the run after first failure.') do |v|
      options[:fail_fast] = v
    end

    opts.on('--verbose', 'Output dumper and dump block names.') do |v|
      options[:verbose] = v
    end

    opts.on('--profile', 'Enable profiling of dumps and list the slowest.') do |v|
      options[:profile] = v
    end

    opts.on('--order TYPE', 'Run dumps by the specified order type.') do |v|
      options[:order] = v
    end

    opts.on('--exclude-response-headers', 'Do not output response headers.') do |v|
      options[:exclude_response_headers] = v
    end

    opts.on('--exclude-timestamp', 'Do not output a timestamp with each dump.') do |v|
      options[:exclude_timestamp] = v
    end
  end.parse!

  options[:filenames] = ARGV

  options.freeze
end


12
13
14
15
16
17
18
# File 'lib/rails_response_dumper/colorize.rb', line 12

def self.print_color(text, color)
  if COLORIZE
    print colorize(text, color)
  else
    print text
  end
end