ActsAsShellscriptExecutable
before:
id | name | script | result |
---|---|---|---|
1 | foo | echo 'lalala' |
execute:
class Script < ActiveRecord::Base
acts_as_shellscript_executable script: :script
end
script = Script.find(1)
script.result = script.execute!
script.save!
after:
id | name | script | result |
---|---|---|---|
1 | foo | echo 'lalala' | lalala\n |
#execute!
#execute!(no args)
- returns the shellscript's stdout of whole of the shellscript
#execute!(block)
- returns
nil
, yields the shellscript's stdout st each line(splited by\n
)
- returns
Options of .acts_as_shellscript_executable
script:
(default::script
)- if
Symbol
, the same name column's value will be evaluated as shellscript - if
String
, the string will be evaluated as shellscript
- if
method:
(default:execute!
)- the execute method's name
command:
(default:'/bin/sh'
)
Options of .acts_as_rubyscript_executable
script:
(default::script
)- if
Symbol
, the same name column's value will be evaluated as shellscript - if
String
, the string will be evaluated as shellscript
- if
method:
(default:ruby_execute!
)- the execute method's name
command:
(default:'ruby'
)- Set path like
'/usr/bin/ruby'
, or array to set option like['ruby', '-c']
,['bundle exec rails', 'r']
- Set path like
Installation
Add this line to your application's Gemfile:
gem 'acts_as_shellscript_executable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install acts_as_shellscript_executable