class Xphase::Spec

Constants

DEBUG
PATH_BASE
PATH_SCRIPT
PATH_SPEC

Attributes

author[R]
dependency[R]
description[R]
id[R]
name[R]
params[R]
template[R]

Public Class Methods

new(val) click to toggle source
Calls superclass method
# File lib/xphase/spec.rb, line 40
def self.new(val)
    @@obj = super(val)

    if @@obj.id.nil?
        return nil
    end
    return @@obj
end
new(id) click to toggle source
# File lib/xphase/spec.rb, line 50
def initialize(id)
    @id = id
    begin
        if ENV["XPHASE_LOCAL"].nil?
            contents  = open(self.specLocation).read
            @template = open(self.scriptLocation).read
        else
            contents  = File.open(self.specLocation, "rb").read
            @template = File.open(self.scriptLocation, "rb").read
        end
    rescue
        @id = nil
        return
    end

    json         = JSON.parse(contents)

    @name        = json["name"]
    @description = json["description"]
    @author      = json["author"]

    @dependency  = json["dependency"]
    @params      = json["params"]

end

Public Instance Methods

script(params) click to toggle source
# File lib/xphase/spec.rb, line 76
def script(params)

    script = @template
    if !params.nil?
        params.each do |key, value|
            if key.eql? "flags"
                script = script + ' ' + value
                next
            end
            script = script.gsub('{{'+key+'}}', value)
        end
    end
    script
end
scriptLocation() click to toggle source
# File lib/xphase/spec.rb, line 31
def scriptLocation
    if ENV["XPHASE_LOCAL"].nil?
        PATH_BASE + @id + PATH_SCRIPT
    else
        Dir.getwd + "/../phases/" + @id + PATH_SCRIPT
    end
end
specLocation() click to toggle source
# File lib/xphase/spec.rb, line 23
def specLocation
    if ENV["XPHASE_LOCAL"].nil?
        PATH_BASE + @id + PATH_SPEC
    else
        Dir.getwd + "/../phases/" + @id + PATH_SPEC
    end
end