Class: ScriptMapper
- Inherits:
-
Object
- Object
- ScriptMapper
- Defined in:
- lib/spinjector/script_mapper.rb
Instance Method Summary collapse
-
#initialize(script_hash) ⇒ ScriptMapper
constructor
A new instance of ScriptMapper.
- #load_script(path) ⇒ Object
- #map ⇒ Object
- #verify_syntax ⇒ Object
Constructor Details
#initialize(script_hash) ⇒ ScriptMapper
Returns a new instance of ScriptMapper.
5 6 7 8 |
# File 'lib/spinjector/script_mapper.rb', line 5 def initialize(script_hash) @script_hash = script_hash verify_syntax end |
Instance Method Details
#load_script(path) ⇒ Object
32 33 34 35 |
# File 'lib/spinjector/script_mapper.rb', line 32 def load_script(path) raise "[Error] File #{path} does not exist" unless !path.nil? && File.exist?(path) File.read(path) end |
#map ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/spinjector/script_mapper.rb', line 10 def map script_code = @script_hash["script"] || load_script(@script_hash["script_path"]) Script.new( @script_hash["name"], script_code, @script_hash["shell_path"] || '/bin/sh', @script_hash["input_paths"] || [], @script_hash["output_paths"] || [], @script_hash["input_file_list_paths"] || [], @script_hash["output_file_list_paths"] || [], @script_hash["dependency_file"], @script_hash["execution_position"] || :before_compile, @script_hash["show_env_vars_in_log"] ) end |
#verify_syntax ⇒ Object
26 27 28 29 30 |
# File 'lib/spinjector/script_mapper.rb', line 26 def verify_syntax raise "[Error] Invalid script description #{@script_hash}" unless @script_hash.is_a?(Hash) raise "[Error] Script must have a name and an associated script" unless @script_hash.has_key?("name") && @script_hash.has_key?("script") || @script_hash.has_key?("script_path") raise "[Error] Invalid name in script #{@script_hash}" unless !@script_hash["name"].nil? end |