acts_as_shellscript_executable 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 030e8454c0d6d951be268f756c079181261df705
4
- data.tar.gz: 199e6144126b46ee7cab835d06eee8c4c9798835
3
+ metadata.gz: 4b5b36e986f4ca4ff2c46a909bd2432362c377c8
4
+ data.tar.gz: 14abb316f1683d19d0cf4258de69e0f3024fe50b
5
5
  SHA512:
6
- metadata.gz: 12f82a5a9c37ba137bfa7cf2a8c33860fd634a4345fa2e748e21ede214a20ce4930ef69ef34414986166f6c41089e84298261305280074bc52526c17cbd2222d
7
- data.tar.gz: 04fa8af167cbbbb104eb7ba321a2f91ec4afad6effa9d7eced3d4e8b2a92bad4f97e0b656ea15817e30d39e80fd431fc8d13f61d9f7d53d6826955574f7b2c57
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 #{configuration[:method]}(&block)
15
- script = @@__configuration__[: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
- class_variable_set(:@@__configuration__, configuration)
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
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module Acts
3
3
  module ShellscriptExecutable
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
6
6
  end
7
7
  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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_shellscript_executable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - hoshinotsuyoshi