exedb 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2edd3f5d079de4f4fe759bc639c12848fdc1b384
4
- data.tar.gz: ea2957752bc6856ed29bc50a1813caa977a46bf4
3
+ metadata.gz: b260ba9f2075f0a3e24dc3329578b8198d75110b
4
+ data.tar.gz: aea82d16176964d1f1907e39815d2ad4223b1035
5
5
  SHA512:
6
- metadata.gz: fb50137af58069d48b51c058f876e268ba46913ce5c0ce1b57a39ad2892ae3919775ee21f42ad9858df3177406ffa098e8e97bc41e45db882b1273866ed39b90
7
- data.tar.gz: d1dcc865f0751ed9115334b9cd6751c532a63f4c839c6b47d9747e0c5a58a93da4f1c6c2b273fb9d7a5f84eb0c5f86d1c06f62f5e80c0a9cbf83c61812123c54
6
+ metadata.gz: 74036155baa5670c00ed225ca1299b810fe7c6002801ca1113d5c94adfa4d99566d33d8d08b353d933e36cda8d0e84a118c44b1b55addd4eae2eefca6ea4bea9
7
+ data.tar.gz: ffa382688d4d13d854fcfaa9e5adc622cbfe5e65229aa336924cc3f87ad64b38c5f3229525c84c0a4a97802ba4406fab22b55a16f8ae348ea7f01248a4df1260
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec
data/Rakefile CHANGED
@@ -1,5 +1,9 @@
1
1
  require 'rake/testtask'
2
+ require "bundler/setup"
3
+
2
4
  Rake::TestTask.new do |t|
3
5
  t.pattern = "spec/*_spec.rb"
6
+ t.verbose = true
4
7
  end
5
8
  require "bundler/gem_tasks"
9
+
@@ -48,9 +48,12 @@ class Exedb
48
48
  IO.popen(@update_method){|pipe|
49
49
  line=pipe.gets
50
50
  while line
51
- file.puts line
52
- file.flush
53
- @content = @content+line
51
+ line=@transform.call(line) if @transform
52
+ if line
53
+ file.puts line
54
+ file.flush
55
+ @content = @content+line
56
+ end
54
57
  line=pipe.gets
55
58
  end
56
59
  }
@@ -60,6 +63,7 @@ class Exedb
60
63
  @content=''
61
64
  @code=-1
62
65
  end
66
+ @content=@alltransform.call(@content,@code) if @alltransform
63
67
  file.write @content
64
68
  file.flush
65
69
  File.open("#{@path}.code",File::RDWR|File::CREAT, 0644){|code_file|
@@ -76,6 +80,45 @@ class Exedb
76
80
  @content
77
81
  end
78
82
 
83
+ #
84
+ # transform each line in command output
85
+ # if nil is returned, line is skipped
86
+ #
87
+ def line_transform(&block)
88
+ if block
89
+ obj = Object.new
90
+ obj.define_singleton_method(:_, &block)
91
+ @transform=obj.method(:_).to_proc
92
+ else
93
+ @transform=nil
94
+ end
95
+ end
96
+
97
+ #
98
+ # cancel transformation each line
99
+ #
100
+ def no_line_transform
101
+ @transform=nil
102
+ end
103
+
104
+ #
105
+ # transform all command output at end of execution
106
+ # block is called with parameters: content, return code
107
+ # returned content replaces original output
108
+ #
109
+ def all_transform(&block)
110
+ if block
111
+ obj = Object.new
112
+ obj.define_singleton_method(:_, &block)
113
+ @alltransform=obj.method(:_).to_proc
114
+ else
115
+ @alltransform=nil
116
+ end
117
+ end
118
+
119
+ def no_all_transform
120
+ @alltransform=nil
121
+ end
79
122
  #
80
123
  # Replace executing command
81
124
  #
@@ -178,4 +221,5 @@ protected
178
221
  file.flock(File::LOCK_UN)
179
222
  }
180
223
  end
224
+
181
225
  end
@@ -1,3 +1,3 @@
1
1
  class Exedb
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -45,7 +45,6 @@ describe Exedb do
45
45
 
46
46
  describe 'parallel istances' do
47
47
  before do
48
- #!!!warn "BEFORE 2>>>>>>>"
49
48
  @db2=Exedb.new
50
49
  @db2.update_method="sleep 1;ls -la #{TEST_DIR}"
51
50
  @db.update
@@ -53,7 +52,6 @@ describe Exedb do
53
52
 
54
53
  it 'reads last cached result' do
55
54
  sleep 2;
56
- #!!!warn ">>>>>>>>>>>>>>>>>>"
57
55
  @db2.get.must_match TEST_FILE
58
56
  end
59
57
 
@@ -109,4 +107,42 @@ describe Exedb do
109
107
  t.join
110
108
  end
111
109
  end
110
+
111
+ describe "transforms output" do
112
+ before do
113
+ @db.line_transform do |str|
114
+ return nil unless str =~ /^([d-])/
115
+ type=$1
116
+ str =~ /(\S+)$/
117
+ prefix= type=='-' ? 'FILE: ' : 'DIR: '
118
+ return "#{prefix}#{$1}"
119
+ end
120
+ end
121
+
122
+ it 'transforms output' do
123
+ @db.get.must_match 'FILE: abc_file'
124
+ end
125
+
126
+ it 'deletes lines in output' do
127
+ x=@db.get
128
+ x.lines.count.must_equal 1
129
+ end
130
+
131
+ it 'cancels transformation' do
132
+ @db.no_line_transform
133
+ x=@db.get
134
+ x.lines.count.must_equal 4
135
+ end
136
+
137
+ it 'transforms each line and all output' do
138
+ @db.all_transform {|str,code| n=str.lines.count; "#{n} lines (#{code})"}
139
+ @db.get.must_equal "1 lines (0)"
140
+ end
141
+
142
+ it 'transforms all raw output' do
143
+ @db.no_line_transform
144
+ @db.all_transform {|str,code| n=str.lines.count; "#{n} lines (#{code})"}
145
+ @db.get.must_equal "4 lines (0)"
146
+ end
147
+ end
112
148
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exedb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Zhumatiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-06 00:00:00.000000000 Z
11
+ date: 2014-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler