Class: Bakery::Command
- Inherits:
-
Object
- Object
- Bakery::Command
- Defined in:
- lib/bakery/command.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #check_for_dependency! ⇒ Object
- #exec(*options) ⇒ Object
-
#initialize(name) ⇒ Command
constructor
A new instance of Command.
- #to_command(*options) ⇒ Object
Constructor Details
#initialize(name) ⇒ Command
Returns a new instance of Command.
7 8 9 10 11 12 13 14 |
# File 'lib/bakery/command.rb', line 7 def initialize(name) raise ArgumentError, 'name must be specified' if '' == name.to_s @name = name.to_s @result = { :out => nil, :err => nil } check_for_dependency! end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/bakery/command.rb', line 5 def name @name end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
5 6 7 |
# File 'lib/bakery/command.rb', line 5 def result @result end |
Instance Method Details
#check_for_dependency! ⇒ Object
16 17 18 19 20 |
# File 'lib/bakery/command.rb', line 16 def check_for_dependency! return true unless '' == `which #{name}`.strip raise MissingSystemDependencyError, "The command line tool #{name} " + 'does not appear to exist on this system, have you installed teTeX?' end |
#exec(*options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bakery/command.rb', line 26 def exec(*) command = to_command() Open3.popen3(command) do |_, stdout, stderr| result[:out] = stdout.readlines.join("\n") result[:err] = stderr.readlines.join("\n") end return result[:out] if '' == result[:err].strip raise ShellCommandCallError, "The command: #{command} failed to " + "execute properly. The output was:\n\n#{result[:out]}\n\nThe error " + "output was:\n\n#{result[:err]}" end |
#to_command(*options) ⇒ Object
22 23 24 |
# File 'lib/bakery/command.rb', line 22 def to_command(*) [name, ()].join(' ') end |