acts_as_shellscript_executable 0.0.2 → 0.0.3
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: 4b5b36e986f4ca4ff2c46a909bd2432362c377c8
|
4
|
+
data.tar.gz: 14abb316f1683d19d0cf4258de69e0f3024fe50b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f28ccb2e65d36b4d8505e3b18d238fcb20e76848f85bb4d56392a2e686c0e0de2526472f021e97c42f2483c3c7f90873ce025561233e8a6645cfdf7b6ff93d55
|
7
|
+
data.tar.gz: 6d1fd98c72e34accf3c3a974473fe0c86991c65cc830cd7e6c371cdb0577ee017d1ba3ff1340ea564aa500b2239c3ed5b068c1693c6a6ad2d4c5cdd0f0defd02
|
@@ -9,17 +9,23 @@ module ActiveRecord
|
|
9
9
|
def acts_as_shellscript_executable(options = {})
|
10
10
|
configuration = { method: :execute!, script: :script }
|
11
11
|
configuration.update(options) if options.is_a?(Hash)
|
12
|
-
|
12
|
+
method = configuration[:method]
|
13
13
|
class_eval <<-EOV
|
14
|
-
def #{
|
15
|
-
script = @@
|
14
|
+
def #{method}(&block)
|
15
|
+
script = @@__configurations__[:#{method}][:script]
|
16
16
|
answer = ''
|
17
17
|
__execute__(script, answer, block)
|
18
18
|
block_given? ? nil : answer
|
19
19
|
end
|
20
20
|
EOV
|
21
21
|
|
22
|
-
|
22
|
+
configurations = begin
|
23
|
+
class_variable_get(:@@__configurations__)
|
24
|
+
rescue NameError
|
25
|
+
{}
|
26
|
+
end
|
27
|
+
configurations[method] = configuration
|
28
|
+
class_variable_set(:@@__configurations__, configurations)
|
23
29
|
include ::ActiveRecord::Acts::ShellscriptExecutable::InstanceMethods
|
24
30
|
end
|
25
31
|
end
|
@@ -85,8 +85,7 @@ describe ActiveRecord::Base do
|
|
85
85
|
context 'given option {script: "echo 1\necho 2"}' do
|
86
86
|
before do
|
87
87
|
class Script < ActiveRecord::Base
|
88
|
-
acts_as_shellscript_executable \
|
89
|
-
script: "echo 1\necho 2"
|
88
|
+
acts_as_shellscript_executable script: "echo 1\necho 2"
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
@@ -104,5 +103,25 @@ describe ActiveRecord::Base do
|
|
104
103
|
end
|
105
104
|
end
|
106
105
|
end
|
106
|
+
|
107
|
+
context 'given option {script: "echo 1\necho 2"}' do
|
108
|
+
before do
|
109
|
+
class Script < ActiveRecord::Base
|
110
|
+
acts_as_shellscript_executable \
|
111
|
+
script: "echo 1\necho 2"
|
112
|
+
acts_as_shellscript_executable \
|
113
|
+
script: "echo 3\necho 4", method: :awesome!
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
it do
|
118
|
+
script = Script.create
|
119
|
+
result = script.execute!
|
120
|
+
awesome_result = script.awesome!
|
121
|
+
|
122
|
+
expect(result).to eq "1\n2\n"
|
123
|
+
expect(awesome_result).to eq "3\n4\n"
|
124
|
+
end
|
125
|
+
end
|
107
126
|
end
|
108
127
|
end
|