tailstrom 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6720202d46441e9ffd7ae73a403b26e14b2bb5e
4
- data.tar.gz: 1e4fb279861cb744697f16b8e912a013ffd58ad8
3
+ metadata.gz: 248be97938bac3cb884cbdb068a7faca0916061f
4
+ data.tar.gz: ac7e4f1466fcfd541ea9f4282161c335e7b96afb
5
5
  SHA512:
6
- metadata.gz: f630928244c74256aa1c488b4d005dd53af9d10a24b92d2d9001cb0cd86110d667b25618855ad8121d24d3309a4b79bc4ec3004d524a3734ae442282fff3ed3d
7
- data.tar.gz: 6bdcbcb947d610518768e24d00f945ec9d35466c5364ab4438f1485ac806f31b057187920b354530bcd2c141fe6f8ef318da67314b6c1d9aabb687fd432f7548
6
+ metadata.gz: 68cd4c9e158940659a5869aa63eb72d9577cc95869dddfe4da682b6dcd3acbe5a6c106a1f91211604c79e678cd97c4634f971a5d6480a6aad29a67aa1db4345f
7
+ data.tar.gz: 656e5d97c582ef745811da3331626da29d44816586a87646104300d8c0f575bdf5018ca8342973c54337156089cf9fc4e2c0f2ba0504704545179d2ea4c6e19a
@@ -34,8 +34,7 @@ module Tailstrom
34
34
  begin
35
35
  sleep @options[:interval]
36
36
 
37
- # TODO refactoring
38
- if printed_lines > 0 && (@counters.size > 1 || @counters.keys != [:nil] && !@counters.empty?)
37
+ if printed_lines > 0 && (@multiline ||= @counters.size > 1)
39
38
  @table.puts
40
39
  printed_lines += 1
41
40
  end
@@ -33,11 +33,11 @@ tail -f access.log | #{$0} [OPTIONS]
33
33
  opt.on('-c file', '--config file', String, 'config file') do |v|
34
34
  @options_from_file = load_config v
35
35
  end
36
- opt.on('-f num', Integer, 'value field') do |v|
37
- @options[:field] = v
36
+ opt.on('-f num_or_string', '--value num_or_string', String, 'value field') do |v|
37
+ @options[:value] = num_or_string v
38
38
  end
39
- opt.on('-k num', Integer, 'key field') do |v|
40
- @options[:key] = v
39
+ opt.on('-k num_or_string', '--key num_or_string', String, 'key field') do |v|
40
+ @options[:key] = num_or_string v
41
41
  end
42
42
  opt.on('-d delimiter', String, 'delimiter') do |v|
43
43
  @options[:delimiter] = v
@@ -79,6 +79,10 @@ tail -f access.log | #{$0} [OPTIONS]
79
79
  File.exist?(value) ? File.read(value) : value
80
80
  end
81
81
 
82
+ def num_or_string(value)
83
+ value =~ /^\d+$/ ? value.to_i : file_or_string(value)
84
+ end
85
+
82
86
  def load_config(file)
83
87
  require 'yaml'
84
88
  argv = []
@@ -30,29 +30,46 @@ module Tailstrom
30
30
 
31
31
  def parse_line(line)
32
32
  col = line.split @options[:delimiter]
33
- value = @options[:field] ? col[@options[:field]] : line
34
- value = format_value value
35
- key = @options[:key] ? col[@options[:key]] : :nil
33
+ key = value = nil
36
34
  in_filter = @options[:in_filter]
37
35
 
38
- scripts = []
36
+ _scripts = []
39
37
 
40
38
  if @options[:map]
41
- scripts << @options[:map]
42
- scripts << 'value=format_value(value)'
39
+ _scripts << @options[:map]
40
+ _scripts << 'value=format_value(value)'
41
+ end
42
+
43
+ if @options[:key]
44
+ _scripts << index_or_eval('key', 'col', @options[:key])
45
+ end
46
+
47
+ if @options[:value]
48
+ _scripts << index_or_eval('value', 'col', @options[:value])
49
+ _scripts << 'value=format_value(value)'
43
50
  end
44
51
 
45
52
  if in_filter
46
- scripts << in_filter
47
- return nil unless eval scripts.join(';')
53
+ _scripts << in_filter
54
+ return nil unless eval _scripts.join(';')
48
55
  end
49
56
 
50
- eval scripts.join(';')
57
+ eval _scripts.join(';')
51
58
  { :line => line, :columns => col, :key => key, :value => value }
52
59
  end
53
60
 
54
61
  def format_value(value)
55
62
  value =~ /\./ ? value.to_f : value.to_i
56
63
  end
64
+
65
+ def index_or_eval(var, col, idx)
66
+ case idx
67
+ when Integer
68
+ "#{var}=col[#{idx}]"
69
+ when String
70
+ "#{var}=#{idx}"
71
+ end
72
+ end
73
+ private :index_or_eval
57
74
  end
58
75
  end
@@ -1,3 +1,3 @@
1
1
  module Tailstrom
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -20,7 +20,7 @@ END
20
20
  139 1,521 958,131 476,502 200
21
21
  END
22
22
 
23
- it { expect(run '-f2 -k3 --map key=key[/[a-z]+/]').to eq <<-END }
23
+ it { expect(run '-f2 --map key=col[3][/[a-z]+/]').to eq <<-END }
24
24
  ---------------------------------------------------
25
25
  count min max avg key
26
26
  ---------------------------------------------------
@@ -29,14 +29,21 @@ END
29
29
  103 1,521 989,278 414,438 photos
30
30
  END
31
31
 
32
- it { expect(run '-f2 -k3 --map key=key[/[a-z]+/] --in-filter key=~/products/').to eq <<-END }
32
+ it { expect(run %!-f2 --key col[3][/[a-z]+/] -e 'key=="products"'!).to eq <<-END }
33
33
  ---------------------------------------------------
34
34
  count min max avg key
35
35
  ---------------------------------------------------
36
36
  104 2,524 995,595 505,832 products
37
37
  END
38
38
 
39
- it { expect(run '-f2 -k3 --map key=key[/[a-z]+/] --sort count').to eq <<-END }
39
+ it { expect(run '-f2 --map key=col[3][/[a-z]+/] --in-filter key=~/products/').to eq <<-END }
40
+ ---------------------------------------------------
41
+ count min max avg key
42
+ ---------------------------------------------------
43
+ 104 2,524 995,595 505,832 products
44
+ END
45
+
46
+ it { expect(run '-f2 --map key=col[3][/[a-z]+/] --sort count').to eq <<-END }
40
47
  ---------------------------------------------------
41
48
  count min max avg key
42
49
  ---------------------------------------------------
@@ -45,7 +52,7 @@ END
45
52
  93 5,584 971,226 485,544 users
46
53
  END
47
54
 
48
- it { expect(run '-f2 -k3 --map key=key[/[a-z]+/] --sort count --order asc').to eq <<-END }
55
+ it { expect(run '-f2 --map key=col[3][/[a-z]+/] --sort count --order asc').to eq <<-END }
49
56
  ---------------------------------------------------
50
57
  count min max avg key
51
58
  ---------------------------------------------------
@@ -54,12 +61,21 @@ END
54
61
  104 2,524 995,595 505,832 products
55
62
  END
56
63
 
57
- it { expect(run '-f2 -k3 --map key=key[/[a-z]+/] --out-filter "min>2000"').to eq <<-END }
64
+ it { expect(run '-f2 --map key=col[3][/[a-z]+/] --out-filter "min>2000"').to eq <<-END }
65
+ ---------------------------------------------------
66
+ count min max avg key
67
+ ---------------------------------------------------
68
+ 104 2,524 995,595 505,832 products
69
+ 93 5,584 971,226 485,544 users
70
+ END
71
+
72
+ it { expect(run '-f2 --map key1=col[3][/[a-z]+/] --key key1').to eq <<-END }
58
73
  ---------------------------------------------------
59
74
  count min max avg key
60
75
  ---------------------------------------------------
61
76
  104 2,524 995,595 505,832 products
62
77
  93 5,584 971,226 485,544 users
78
+ 103 1,521 989,278 414,438 photos
63
79
  END
64
80
 
65
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tailstrom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Issei Naruta