Class: OSC::VNC::ScriptView
- Inherits:
-
Mustache
- Object
- Mustache
- OSC::VNC::ScriptView
- Defined in:
- lib/osc/vnc/scriptview.rb
Overview
Provides a view for the PBS batch script configured as a mustache template in templates/script/vnc.mustache. Extra options can be passed to this view and accessed directly in the mustache template.
Instance Method Summary collapse
-
#initialize(type, cluster, opts = {}) ⇒ ScriptView
constructor
A new instance of ScriptView.
-
#method_missing(method_name, *arguments, &block) ⇒ Object
See if the method call exists as a key in @view_context.
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Checks if the method responds to an instance method, or is able to proxy it to @view_context.
-
#valid? ⇒ Boolean
Determine whether the script is valid or not.
Constructor Details
#initialize(type, cluster, opts = {}) ⇒ ScriptView
Returns a new instance of ScriptView.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/osc/vnc/scriptview.rb', line 17 def initialize(type, cluster, opts = {}) self.template_name = type # Read in pre-configured options script_cfg = YAML.load_file("#{CONFIG_PATH}/script.yml").fetch(type.to_s, {}) subtype_opts = script_cfg[opts[:subtype].to_s] || script_cfg['default'] cluster_opts = subtype_opts.fetch('cluster', {}).fetch(cluster, {}) context = subtype_opts.merge cluster_opts @view_context = {} context.each do |key, value| @view_context[key.to_sym] = value end @view_context.merge! opts @view_context[:cluster] = cluster end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
See if the method call exists as a key in @view_context.
49 50 51 |
# File 'lib/osc/vnc/scriptview.rb', line 49 def method_missing(method_name, *arguments, &block) @view_context.fetch(method_name) { super } end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Checks if the method responds to an instance method, or is able to proxy it to @view_context.
58 59 60 |
# File 'lib/osc/vnc/scriptview.rb', line 58 def respond_to_missing?(method_name, include_private = false) @view_context.include?(method_name) || super end |
#valid? ⇒ Boolean
Determine whether the script is valid or not
38 39 40 41 42 |
# File 'lib/osc/vnc/scriptview.rb', line 38 def valid? raise InvalidPath, "xstartup script is not found" unless File.file?(xstartup) raise InvalidPath, "output directory is a file" if File.file?(outdir) FileUtils.mkdir_p(outdir) end |