Class: Xphase::Spec

Inherits:
Object
  • Object
show all
Defined in:
lib/xphase/spec.rb

Constant Summary collapse

DEBUG =
true
PATH_BASE =
"https://raw.githubusercontent.com/CoreKit/xphase/master/phases/"
PATH_SPEC =
"/spec.json"
PATH_SCRIPT =
"/script.sh"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Spec

Returns a new instance of Spec.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



16
17
18
# File 'lib/xphase/spec.rb', line 16

def author
  @author
end

#dependencyObject (readonly)

Returns the value of attribute dependency.



18
19
20
# File 'lib/xphase/spec.rb', line 18

def dependency
  @dependency
end

#descriptionObject (readonly)

Returns the value of attribute description.



15
16
17
# File 'lib/xphase/spec.rb', line 15

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/xphase/spec.rb', line 12

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/xphase/spec.rb', line 14

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



19
20
21
# File 'lib/xphase/spec.rb', line 19

def params
  @params
end

#templateObject (readonly)

Returns the value of attribute template.



21
22
23
# File 'lib/xphase/spec.rb', line 21

def template
  @template
end

Class Method Details

.new(val) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/xphase/spec.rb', line 40

def self.new(val)
    @@obj = super(val)

    if @@obj.id.nil?
        return nil
    end
    return @@obj
end

Instance Method Details

#script(params) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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

#scriptLocationObject



31
32
33
34
35
36
37
# 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

#specLocationObject



23
24
25
26
27
28
29
# 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