class Aruba::ScriptFile
Generate script files on command line
Attributes
content[R]
interpreter[R]
path[R]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/aruba/generators/script_file.rb, line 11 def initialize(opts = {}) @path = opts[:path] @content = opts[:content] @interpreter = opts[:interpreter] end
Public Instance Methods
call()
click to toggle source
# File lib/aruba/generators/script_file.rb, line 17 def call Aruba.platform.write_file(path, "#{header}#{content}") Aruba.platform.chmod(0o755, path, {}) end
Private Instance Methods
header()
click to toggle source
# File lib/aruba/generators/script_file.rb, line 24 def header if script_starts_with_shebang? "" elsif interpreter_is_absolute_path? format("#!%s\n", interpreter) elsif interpreter_is_just_the_name_of_shell? format("#!/usr/bin/env %s\n", interpreter) end end
interpreter_is_absolute_path?()
click to toggle source
# File lib/aruba/generators/script_file.rb, line 34 def interpreter_is_absolute_path? Aruba.platform.absolute_path? interpreter end
interpreter_is_just_the_name_of_shell?()
click to toggle source
# File lib/aruba/generators/script_file.rb, line 38 def interpreter_is_just_the_name_of_shell? interpreter =~ /^[-_a-zA-Z.]+$/ end
script_starts_with_shebang?()
click to toggle source
# File lib/aruba/generators/script_file.rb, line 42 def script_starts_with_shebang? content.start_with? "#!" end