freydis 0.0.3 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Binary file
data/lib/freydis/data.rb DELETED
@@ -1,43 +0,0 @@
1
- # lib/data.rb
2
-
3
- require 'yaml'
4
-
5
- module Freydis
6
- class Data
7
- attr_accessor :options
8
-
9
- def initialize(config_file, data = {})
10
- @config_file = config_file ||= "#{ENV['HOME']}/.config/freydis/freydis.yaml"
11
- @options = parse(data)
12
- end
13
-
14
- def parse(data)
15
- disk = data[:disk] ? data[:disk] : ""
16
- paths = data[:paths] ? data[:paths] : []
17
- opts = {
18
- :disk => disk,
19
- :paths => paths
20
- }
21
- opts
22
- end
23
-
24
- def load!
25
- if File.exist? @config_file
26
- datas = YAML.load_file @config_file
27
- @options.merge!(datas)
28
- else
29
- save
30
- STDERR.puts "Initialized config at #{@config_file}"
31
- end
32
- end
33
-
34
- def save
35
- conf_dir = "#{ENV['HOME']}/.config/freydis"
36
- Dir.mkdir conf_dir unless Dir.exist? conf_dir
37
-
38
- File.open(@config_file, 'w') { |f|
39
- YAML::dump(@options, f)
40
- }
41
- end
42
- end
43
- end
data/lib/freydis/init.rb DELETED
@@ -1,76 +0,0 @@
1
- # lib/init.rb
2
-
3
- module Freydis
4
- module Init
5
- def self.run(options)
6
- loop do
7
- puts %q{Please select an option:
8
-
9
- 1. Choose a disk (plug on)
10
- 2. Add more paths
11
- 3. Reset paths
12
- 4. Show options
13
- 5. Save & Quit}
14
-
15
- print "\n> "
16
- case gets.chomp
17
- when '1'
18
- select_disk(options)
19
- when '2'
20
- puts "Add a path..."
21
- add_path(options)
22
- when '3'
23
- puts "Reseting paths..."
24
- options[:paths] = []
25
- when '4'
26
- show_options(options)
27
- else
28
- return
29
- end
30
- end
31
- end
32
-
33
- private
34
-
35
- def self.select_disk(options)
36
- disks_list = Dir.glob("/dev/sd?")
37
- puts "Available disks: (only type sdX)"
38
- disks_list.each { |disk_list|
39
- d = disk_list.delete_prefix("/dev/")
40
- your_disk = Freydis::Disk.new(d)
41
- puts "+ " + your_disk.complete_info
42
- }
43
- print "> "
44
- answer = $stdin.gets
45
- disk = answer.chomp
46
- if disk != ''
47
- options[:disk] = Freydis::Guard::disk(disk)
48
- puts "Disk #{disk} added."
49
- else
50
- puts "No disk added."
51
- end
52
- end
53
-
54
- def self.add_path(options)
55
- print "> "
56
- answer = $stdin.gets
57
- new_path = answer.chomp if answer
58
- if Dir.exists? new_path
59
- options[:paths] << new_path
60
- puts "Path '#{new_path}' added"
61
- display_path(options)
62
- else
63
- puts "[-] Path no found."
64
- end
65
- end
66
-
67
- def self.display_path(options)
68
- puts "Current paths:"
69
- options[:paths].each { |p| puts "+ #{p}" }
70
- end
71
-
72
- def self.show_options(options)
73
- puts options
74
- end
75
- end
76
- end