Top Level Namespace

Defined Under Namespace

Modules: ATK, ATKIO, AtkToolbox, OS Classes: Apt, AtkPaths, Code, ConsoleCode, FileSys, Homebrew, Info, PackageManager, Pacman, RubyCode, Scoop, String, Version, YamlEdit, Yum, ZipFileGenerator

Constant Summary collapse

VERSION_OF_RUBY =
Version.new(RUBY_VERSION)
HOME =

windows

`echo %HOMEPATH%`.chomp
FS =

create an FS alias

FileSys

Instance Method Summary collapse

Instance Method Details

#ask_yes_or_no(question) ⇒ Object

Q&A Functions

TODO: replace these with github.com/piotrmurach/tty-prompt



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/atk/cmd.rb', line 30

def ask_yes_or_no(question)
    loop do 
        puts question
        case gets.chomp
        when /\A\s*(yes|yeah|y)\z\s*/i
            return true
        when /\A\s*(no|nope|n)\z\s*/i
            return false
        when /\A\s*cancel\s*\z/i
            raise 'user canceled yes or no question'
        else
            puts "Sorry, please answer 'yes', 'no', or 'cancel'"
        end#case
    end#loop 
end

#commandline_argsObject

extract all the command line input so STDIN can be used



4
5
6
7
8
9
10
11
# File 'lib/atk/cmd.rb', line 4

def commandline_args() 
    the_args = []
    for each in ARGV
        the_args << each
    end
    ARGV.clear
    return the_args
end

#inject_string(string, middle_part, start_line, start_column, end_line, end_column) ⇒ Object

doc = <<-HEREDOC (dependencies):

python: 3.6.7
gcc: 8.0.0

HEREDOC document = YamlEdit.new(string:doc) document[“python”].replace_value_with(value: “200”) puts document.string # creates: doc = <<-HEREDOC (dependencies):

python: "200"
gcc: 8.0.0

HEREDOC



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/atk/extra_yaml.rb', line 43

def inject_string(string, middle_part, start_line, start_column, end_line, end_column)
    lines = string.split("\n")
    untouched_begining_lines = lines[0...start_line]
    untouched_ending_lines   = lines[end_line+1..-1]
    middle_lines = []

    before_part = lines[start_line][0...start_column]
    after_part = lines[end_line][end_column..-1]

    return (untouched_begining_lines + [ before_part + middle_part + after_part ] + untouched_ending_lines).join("\n")
end

#online?Boolean

Returns:

  • (Boolean)


1
2
3
4
5
6
7
8
# File 'lib/atk/online.rb', line 1

def online?
    require 'open-uri'
    begin
        true if open("http://www.google.com/")
    rescue
        false
    end
end

#register_tag(tag_name, class_value) ⇒ Object

Create loaders for ruby code literal and console code literal



12
13
14
15
# File 'lib/atk/yaml_info_parser.rb', line 12

def register_tag(tag_name, class_value)
    YAML.add_tag(tag_name, class_value)
    Code.tags[tag_name] = class_value
end

#set_command(name, code) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/atk/set_command.rb', line 5

def set_command(name, code)
    if OS.is?("unix")
        exec_path = "/usr/local/bin/#{name}"
        local_place = ATK.temp_path(name)
        # add the hash bang
        hash_bang = "#!#{ATK.paths[:ruby]}\n"
        # create the file
        FS.write(hash_bang+code, to: local_place)
        # copy to command folder
        system("sudo", "cp", local_place, exec_path)
        system("sudo", "chmod", "ugo+x", exec_path)
    elsif OS.is?("windows")
        # check for invalid file paths, see https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
        if name =~ /[><:"\/\\|?*]/
            puts "Sorry #{name} isn't a valid file path on windows"
            return ""
        end
        username = FS.username
        exec_path = "C:\\Users\\#{username}\\AppData\\local\\Microsoft\\WindowsApps\\#{name}"
        
        # create the code
        IO.write(exec_path+".rb", code)
        # create an executable to call the code
        FS.write(exec_path+".bat", "@echo off\nruby \"#{exec_path}.rb\" %*")
    end
end

#zip(source, destination = nil) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/atk/zip.rb', line 47

def zip(source, destination=nil)
    if destination == nil
        destination = source + ".zip"
    end
    
    zip_helper = ZipFileGenerator.new(source, destination)
    zip_helper.write()
end