Module: Swineherd::Script::Common
- Included in:
- HadoopScript, PigScript, RScript, WukongScript
- Defined in:
- lib/swineherd/script.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#input ⇒ Object
Returns the value of attribute input.
-
#options ⇒ Object
Returns the value of attribute options.
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
-
#cmd ⇒ Object
This depends on the type of script.
-
#env ⇒ Object
Allows for setting the environment the script will be ran in.
- #initialize(source, input = [], output = [], options = {}, attributes = {}) ⇒ Object
-
#local_cmd ⇒ Object
Override this in subclass to decide how script runs in ‘local’ mode Best practice is that it needs to be able to run on a laptop w/o hadoop.
-
#refresh! ⇒ Object
So we can reuse ourselves.
-
#run(mode = :hadoop) ⇒ Object
Default is to run with hadoop.
- #script ⇒ Object
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
10 11 12 |
# File 'lib/swineherd/script.rb', line 10 def attributes @attributes end |
#input ⇒ Object
Returns the value of attribute input.
10 11 12 |
# File 'lib/swineherd/script.rb', line 10 def input @input end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/swineherd/script.rb', line 10 def @options end |
#output ⇒ Object
Returns the value of attribute output.
10 11 12 |
# File 'lib/swineherd/script.rb', line 10 def output @output end |
Instance Method Details
#cmd ⇒ Object
This depends on the type of script
42 43 44 |
# File 'lib/swineherd/script.rb', line 42 def cmd raise "Override this in subclass!" end |
#env ⇒ Object
Allows for setting the environment the script will be ran in
22 23 24 |
# File 'lib/swineherd/script.rb', line 22 def env ENV end |
#initialize(source, input = [], output = [], options = {}, attributes = {}) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/swineherd/script.rb', line 11 def initialize(source, input = [], output = [], = {}, attributes ={}) @source = source @input = input @output = output @options = @attributes = attributes end |
#local_cmd ⇒ Object
Override this in subclass to decide how script runs in ‘local’ mode Best practice is that it needs to be able to run on a laptop w/o hadoop.
51 52 53 |
# File 'lib/swineherd/script.rb', line 51 def local_cmd raise "Override this in subclass!" end |
#refresh! ⇒ Object
So we can reuse ourselves
33 34 35 36 37 |
# File 'lib/swineherd/script.rb', line 33 def refresh! @script = nil @output = [] @input = [] end |
#run(mode = :hadoop) ⇒ Object
Default is to run with hadoop
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/swineherd/script.rb', line 58 def run mode=:hadoop command = case mode when :local then local_cmd when :hadoop then cmd end sh command do |ok, status| ok or raise "#{mode.to_s.capitalize} mode script failed with exit status #{status}" end end |
#script ⇒ Object
26 27 28 |
# File 'lib/swineherd/script.rb', line 26 def script @script ||= Template.new(@source, @attributes).substitute! end |