acts_as_shellscript_executable 0.0.1 → 0.0.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 030e8454c0d6d951be268f756c079181261df705
|
4
|
+
data.tar.gz: 199e6144126b46ee7cab835d06eee8c4c9798835
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12f82a5a9c37ba137bfa7cf2a8c33860fd634a4345fa2e748e21ede214a20ce4930ef69ef34414986166f6c41089e84298261305280074bc52526c17cbd2222d
|
7
|
+
data.tar.gz: 04fa8af167cbbbb104eb7ba321a2f91ec4afad6effa9d7eced3d4e8b2a92bad4f97e0b656ea15817e30d39e80fd431fc8d13f61d9f7d53d6826955574f7b2c57
|
data/README.md
CHANGED
@@ -33,7 +33,7 @@ script.save!
|
|
33
33
|
|
34
34
|
## #execute!
|
35
35
|
|
36
|
-
* `#execute!(
|
36
|
+
* `#execute!(no args)`
|
37
37
|
* returns scripts stdout of whole of the shellscript
|
38
38
|
|
39
39
|
* `#execute!(block)`
|
@@ -45,9 +45,6 @@ script.save!
|
|
45
45
|
* if `Symbol`, the same name column's value will be evaluated as shellscript
|
46
46
|
* if `String`, the string will be evaluated as shellscript
|
47
47
|
|
48
|
-
* `parallel:` (default: `false`)
|
49
|
-
* if true, the script will run in parallel by using `thread`
|
50
|
-
|
51
48
|
* `method:` (default: `execute!`)
|
52
49
|
* the execute method's name
|
53
50
|
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'thread'
|
2
|
-
|
3
1
|
module ActiveRecord
|
4
2
|
module Acts
|
5
3
|
module ShellscriptExecutable
|
@@ -16,15 +14,8 @@ module ActiveRecord
|
|
16
14
|
def #{configuration[:method]}(&block)
|
17
15
|
script = @@__configuration__[:script]
|
18
16
|
answer = ''
|
19
|
-
|
20
|
-
|
21
|
-
__execute__(script, answer, block)
|
22
|
-
end
|
23
|
-
block_given? ? nil : answer
|
24
|
-
else
|
25
|
-
__execute__(script, answer, block)
|
26
|
-
block_given? ? nil : answer
|
27
|
-
end
|
17
|
+
__execute__(script, answer, block)
|
18
|
+
block_given? ? nil : answer
|
28
19
|
end
|
29
20
|
EOV
|
30
21
|
|
@@ -38,40 +38,6 @@ describe ActiveRecord::Base do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
describe 'given option parallel' do
|
42
|
-
context 'given option {script: :script, parallel: false}' do
|
43
|
-
before do
|
44
|
-
class Script < ActiveRecord::Base
|
45
|
-
acts_as_shellscript_executable script: :script, parallel: false
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it do
|
50
|
-
script = Script.create
|
51
|
-
script.script = 'echo $PPID'
|
52
|
-
expect(script.execute!).to eq "#{Process.pid}\n"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'given option {script: :script, parallel: true}' do
|
57
|
-
before do
|
58
|
-
class Script < ActiveRecord::Base
|
59
|
-
acts_as_shellscript_executable script: :script, parallel: true
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it do
|
64
|
-
script = Script.create
|
65
|
-
script.script = "sleep 1\necho $PPID"
|
66
|
-
result = script.execute!
|
67
|
-
|
68
|
-
expect(result).to eq('')
|
69
|
-
sleep 1.5
|
70
|
-
expect(result).to eq("#{Process.pid}\n")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
41
|
context 'given option { script: :script2 }' do
|
76
42
|
before do
|
77
43
|
class Script < ActiveRecord::Base
|
@@ -116,31 +82,6 @@ describe ActiveRecord::Base do
|
|
116
82
|
end
|
117
83
|
end
|
118
84
|
|
119
|
-
context 'given option {script: "echo 1\nsleep 1\necho 2" parallel: true}' do
|
120
|
-
before do
|
121
|
-
class Script < ActiveRecord::Base
|
122
|
-
acts_as_shellscript_executable \
|
123
|
-
script: "echo 1\nsleep 1\necho 2", parallel: true
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe 'block given' do
|
128
|
-
it do
|
129
|
-
script = Script.create
|
130
|
-
watcher = []
|
131
|
-
|
132
|
-
retval = script.execute! do |each_line_result|
|
133
|
-
watcher << each_line_result
|
134
|
-
end
|
135
|
-
|
136
|
-
sleep 2
|
137
|
-
|
138
|
-
expect(retval).to be_nil
|
139
|
-
expect(watcher).to eq ["1\n", '', "2\n"]
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
85
|
context 'given option {script: "echo 1\necho 2"}' do
|
145
86
|
before do
|
146
87
|
class Script < ActiveRecord::Base
|
@@ -163,30 +104,5 @@ describe ActiveRecord::Base do
|
|
163
104
|
end
|
164
105
|
end
|
165
106
|
end
|
166
|
-
|
167
|
-
context 'given option {method: :awesome!}' do
|
168
|
-
before do
|
169
|
-
class Script < ActiveRecord::Base
|
170
|
-
acts_as_shellscript_executable \
|
171
|
-
method: :awesome!, script: "echo 1\nsleep 1\necho 2", parallel: true
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
describe 'block given' do
|
176
|
-
it do
|
177
|
-
script = Script.create
|
178
|
-
watcher = []
|
179
|
-
|
180
|
-
retval = script.awesome! do |each_line_result|
|
181
|
-
watcher << each_line_result
|
182
|
-
end
|
183
|
-
|
184
|
-
sleep 2
|
185
|
-
|
186
|
-
expect(retval).to be_nil
|
187
|
-
expect(watcher).to eq ["1\n", '', "2\n"]
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
107
|
end
|
192
108
|
end
|