xail 0.0.2 → 0.0.3
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.
- data/TODO.md +8 -0
- data/examples/logview.xail.rb +1 -2
- data/lib/xail.rb +1 -11
- data/lib/xail/config.rb +27 -19
- data/lib/xail/filter.rb +3 -1
- data/lib/xail/ui.rb +2 -7
- data/lib/xail/version.rb +1 -1
- data/spec/config_spec.rb +17 -0
- metadata +11 -8
data/TODO.md
ADDED
data/examples/logview.xail.rb
CHANGED
data/lib/xail.rb
CHANGED
@@ -16,17 +16,7 @@ A Ruby utility for performing basic stream processing, directly focused on incre
|
|
16
16
|
|
17
17
|
|
18
18
|
def Xail.run(configuration)
|
19
|
-
|
20
|
-
begin
|
21
|
-
extend Xail::DSL
|
22
|
-
|
23
|
-
eval(configuration)
|
24
|
-
filter = filter_in_scope
|
25
|
-
|
26
|
-
if !has_final
|
27
|
-
filter << PassThroughFilter.new
|
28
|
-
end
|
29
|
-
end
|
19
|
+
filter = Xail.build_from_config(configuration)
|
30
20
|
|
31
21
|
stream = $stdin
|
32
22
|
stream.each() do |line|
|
data/lib/xail/config.rb
CHANGED
@@ -2,18 +2,35 @@
|
|
2
2
|
require 'xail/filter'
|
3
3
|
|
4
4
|
module Xail
|
5
|
+
def self.build_from_config(configuration)
|
6
|
+
begin
|
7
|
+
extend Xail::DSL
|
8
|
+
eval(configuration)
|
9
|
+
|
10
|
+
filter = filter_in_scope
|
11
|
+
|
12
|
+
if !has_final
|
13
|
+
filter << PassThroughFilter.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
return filter
|
18
|
+
end
|
19
|
+
|
5
20
|
module DSL
|
6
21
|
def get_binding
|
7
22
|
binding
|
8
23
|
end
|
9
24
|
|
10
25
|
def filter_scope(compound)
|
26
|
+
# add this compound filter to the filter currently in scope
|
11
27
|
filter_in_scope << compound
|
12
|
-
@filter_stack << compound
|
13
|
-
|
14
|
-
yield
|
15
28
|
|
16
|
-
|
29
|
+
if block_given?
|
30
|
+
@filter_stack << compound
|
31
|
+
yield
|
32
|
+
@filter_stack.pop
|
33
|
+
end
|
17
34
|
end
|
18
35
|
|
19
36
|
def filter(&block)
|
@@ -24,16 +41,9 @@ module Xail
|
|
24
41
|
end
|
25
42
|
end
|
26
43
|
|
27
|
-
# TODO add support for explicitly listing sources
|
28
|
-
#def stream(name, source = null)
|
29
|
-
# source ||= name
|
30
|
-
#end
|
31
|
-
|
32
44
|
def group(name, &filters)
|
33
45
|
# TODO intergrate with UX
|
34
|
-
filter_scope(FilterComposition.new)
|
35
|
-
filters.yield
|
36
|
-
}
|
46
|
+
filter_scope(FilterComposition.new, &filters)
|
37
47
|
end
|
38
48
|
|
39
49
|
attr :has_final
|
@@ -55,15 +65,13 @@ module Xail
|
|
55
65
|
|
56
66
|
def method_missing(name, *args, &block)
|
57
67
|
abort "internal error #{name} #{args} #{block}" unless name
|
68
|
+
|
58
69
|
filterClass = FilterRegistry::get_filter(name.downcase)
|
59
|
-
filter_scope(filterClass.new(*args))
|
60
|
-
block.yield if block
|
61
|
-
end
|
62
|
-
filter_in_scope << filter
|
70
|
+
filter_scope(filterClass.new(*args), &block)
|
63
71
|
|
64
|
-
# short circuit the stream line stop exception so we can catch it
|
65
|
-
# in xail main
|
66
72
|
rescue StreamLineStop => stop
|
73
|
+
# short circuit the stream line stop exception so we can catch it
|
74
|
+
# in xail main
|
67
75
|
raise stop
|
68
76
|
|
69
77
|
rescue UnknownFilter => error
|
@@ -73,4 +81,4 @@ module Xail
|
|
73
81
|
abort "#{filter_in_scope} will not accept #{name} as subfilter: #{error}"
|
74
82
|
end
|
75
83
|
end
|
76
|
-
end
|
84
|
+
end
|
data/lib/xail/filter.rb
CHANGED
@@ -70,6 +70,8 @@ module Xail
|
|
70
70
|
#
|
71
71
|
|
72
72
|
class AbstractCompoundFilter < AbstractFilter
|
73
|
+
attr_reader :filters
|
74
|
+
|
73
75
|
def initialize
|
74
76
|
@filters = []
|
75
77
|
end
|
@@ -280,4 +282,4 @@ module Xail
|
|
280
282
|
class Underscore < AbstractColorFilter; end
|
281
283
|
class Negative < AbstractColorFilter; end
|
282
284
|
class Dark < AbstractColorFilter; end
|
283
|
-
end
|
285
|
+
end
|
data/lib/xail/ui.rb
CHANGED
data/lib/xail/version.rb
CHANGED
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'xail/config'
|
2
|
+
|
3
|
+
include Xail
|
4
|
+
|
5
|
+
describe Config do
|
6
|
+
it "should support a trivial filter" do
|
7
|
+
filter = build_from_config <<-CONF
|
8
|
+
group('main') {
|
9
|
+
contains 'cat'
|
10
|
+
red
|
11
|
+
}
|
12
|
+
CONF
|
13
|
+
|
14
|
+
filter.streamLine('dog').should eq('dog')
|
15
|
+
filter.streamLine('cat').should eq("\e[31mcat\e[0m")
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-26 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70282585842340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70282585842340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: trollop
|
27
|
-
requirement: &
|
27
|
+
requirement: &70282585841900 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70282585841900
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: term-ansicolor
|
38
|
-
requirement: &
|
38
|
+
requirement: &70282585841400 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70282585841400
|
47
47
|
description: A lightweight Ruby DSL for building text-stream filters
|
48
48
|
email:
|
49
49
|
- wiktor@tumblr.com
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- Gemfile
|
57
57
|
- README.md
|
58
58
|
- Rakefile
|
59
|
+
- TODO.md
|
59
60
|
- bin/xail
|
60
61
|
- examples/customfilter.xail.rb
|
61
62
|
- examples/logview.xail.rb
|
@@ -65,6 +66,7 @@ files:
|
|
65
66
|
- lib/xail/filter.rb
|
66
67
|
- lib/xail/ui.rb
|
67
68
|
- lib/xail/version.rb
|
69
|
+
- spec/config_spec.rb
|
68
70
|
- spec/filter_spec.rb
|
69
71
|
- xail.gemspec
|
70
72
|
homepage: ''
|
@@ -92,4 +94,5 @@ signing_key:
|
|
92
94
|
specification_version: 3
|
93
95
|
summary: tail for winners
|
94
96
|
test_files:
|
97
|
+
- spec/config_spec.rb
|
95
98
|
- spec/filter_spec.rb
|