Class: Jumpstarter::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/jumpstarter_core/setup.rb

Class Method Summary collapse

Class Method Details

.eval_file(file_text) ⇒ Object

File.delete(“Starter.rb”)



91
92
93
# File 'lib/jumpstarter_core/setup.rb', line 91

def eval_file(file_text)
    eval(cmd_file)
end

.fill_with_inst!Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/jumpstarter_core/setup.rb', line 52

def fill_with_inst!()
    text = ""
    rel_files = [
        "instructions.rb", 
        "commands.rb", 
        "commandRunner.rb",
        "OS.rb", 
        "xcode_helper.rb", 
        "Writer.rb", 
        "git.rb", 
        "bash.rb", 
        "xcode.rb", 
        "pip.rb"
    ]
    rel_files.each do |f|
        File.open(__dir__ + "/#{f}", "r") do |f|
            f.each_line do |line|
                text = "#{text}#{line}"
            end
        end
        text = "#{text}\n"
    end

    return text
end

.find!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jumpstarter_core/setup.rb', line 21

def find!()
    ## Find path to Starter file
    file_path = ""
    path = Dir.glob("./**/#{Jumpstarter::FILE}")
    if path.length == 1
        puts "Found Setup file at #{path[0]}"
        file_path = path[0]
    else
        puts "We found multiple Starter files in this directory tree"
        puts "Please select the one you want to use by typing the number that corrisponds to that file below"
        puts options(path)
        puts "Choose file #"
        num = (STDIN.gets.chomp).to_i
        file_path = path[num]
    end
    return file_path
end

.options(ops) ⇒ Object

HELPER METHOD



11
12
13
14
15
16
17
18
19
# File 'lib/jumpstarter_core/setup.rb', line 11

def options(ops)
    rows = []
    c = 0
    ops.each do |v|
        rows << [v, c]
        c = c + 1
    end
    return Terminal::Table.new :rows => rows
end

.parse_into_inst(line) ⇒ Object



42
43
44
# File 'lib/jumpstarter_core/setup.rb', line 42

def parse_into_inst(line)
    return Jumpstarter::InstructionParser.parse(line)
end

.proccess_file(path) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/jumpstarter_core/setup.rb', line 77

def proccess_file(path)
    puts "Processing file #{path}"
    cmd_file = fill_with_inst!
    File.open(path, "r") do |f|
        f.each_line do |line|
            inst = parse_into_inst(line)
            cmd_file = "#{cmd_file}\n#{inst}"
        end
    end
    # Setup.eval_file(cmd_file)
    File.open("Starter.rb", 'w') { |file| file.write(cmd_file) }
    system("ruby Starter.rb")
    # File.delete("Starter.rb")
end

.process_instruction(inst) ⇒ Object



46
47
48
49
50
# File 'lib/jumpstarter_core/setup.rb', line 46

def process_instruction(inst)
    puts "[Next Instruction]"
    result = inst.run!
    return result
end

.setup!Object



38
39
40
# File 'lib/jumpstarter_core/setup.rb', line 38

def setup!()
    proccess_file(Setup.find!)
end