Class: OSC::VNC::ScriptView

Inherits:
Mustache
  • Object
show all
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

Constructor Details

#initialize(type, cluster, opts = {}) ⇒ ScriptView

Returns a new instance of ScriptView.

Parameters:

  • type (Symbol)

    The script type defined in config/script.yml (:vnc or :server).

  • cluster (String)

    The cluster the job will run on defined in config/script.yml.

  • opts (Hash) (defaults to: {})

    The options used to construct PBS batch script view.

Options Hash (opts):

  • :subtype (Symbol)

    The subtype (i.e., :default or :shared) outlined in config/script.yml.



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.

Parameters:

  • method_name

    the method name called

  • arguments

    the arguments to the call

  • block

    an optional block for the call



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.

Parameters:

  • method_name

    the method name to check

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)

    Whether this is a valid script.

Raises:

  • (InvalidPath)

    if { #xstartup } or { #outdir } do not correspond to actual file system locations



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