Class: Roebe::Shell::ShellrcParser
- Inherits:
-
Object
- Object
- Roebe::Shell::ShellrcParser
show all
- Defined in:
- lib/roebe/shell/shellrc_parser/shellrc_parser.rb
Overview
Roebe::Shell::ShellrcParser
Constant Summary
collapse
- NAMESPACE =
inspect
- HOME_DIR =
'/root/'
- DEFAULT_ROEBESHELLRC_FILE_LOCATION =
#
DEFAULT_ROEBESHELLRC_FILE_LOCATION
Where the roebeshellrc file is usually stored.
#
HOME_DIR+'RoebeShell/roebeshellrc'
Class Method Summary
collapse
-
.path_to_main_file? ⇒ Boolean
# === Roebe::Shell::ShellrcParser.path_to_main_file? ========================================================================= #.
Instance Method Summary
collapse
Constructor Details
#initialize(i = nil, run_already = true) ⇒ ShellrcParser
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 56
def initialize(
i = nil,
run_already = true
)
reset
set_location_to_the_roebeshellrc_file(i)
if block_given?
yielded = yield
if yielded.is_a?(Hash) and yielded.has_key?(:debug)
yielded = yielded.delete(:debug)
if yielded == true
enable_debug
else
disable_debug
end
end
end
run if run_already
end
|
Class Method Details
.path_to_main_file? ⇒ Boolean
#
Roebe::Shell::ShellrcParser.path_to_main_file?
#
Instance Method Details
#add_option_to_main_hash(this_key, this_value = nil) ⇒ Object
Also known as:
set_in_main_hash
#
add_option_to_main_hash
We store the keys as Strings always.
#
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 130
def add_option_to_main_hash(
this_key, this_value = nil
)
this_key = this_key.to_s
case this_key
when 'colours','colors' this_key = 'use_colours'
end
@hash[this_key] = this_value
end
|
#consider_displaying_the_dataset_to_the_user ⇒ Object
#
consider_displaying_the_dataset_to_the_user
#
159
160
161
162
163
164
165
166
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 159
def consider_displaying_the_dataset_to_the_user
if @debug
opne 'We have enabled debugging for this class, thus we will '\
'show more information.'
opne 'The dataset is:'
pp dataset?
end
end
|
#dataset? ⇒ Boolean
Also known as:
dataset
121
122
123
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 121
def dataset?
@dataset
end
|
#disable_debug ⇒ Object
178
179
180
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 178
def disable_debug
@debug = false
end
|
#enable_debug ⇒ Object
Also known as:
do_debug
171
172
173
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 171
def enable_debug
@debug = true
end
|
#hash? ⇒ Boolean
90
91
92
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 90
def hash?
@hash
end
|
#location_to_the_roebeshellrc_file? ⇒ Boolean
Also known as:
input?
#
location_to_the_roebeshellrc_file?
#
114
115
116
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 114
def location_to_the_roebeshellrc_file?
@location_to_the_roebeshellrc_file
end
|
185
186
187
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 185
def opnn
Opn.opn(namespace: NAMESPACE)
end
|
79
80
81
82
83
84
85
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 79
def reset
set_location_to_the_roebeshellrc_file @debug = false @hash = {}
@dataset = nil
set_in_main_hash(:colours, nil)
end
|
256
257
258
259
260
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 256
def run
try_to_assign_the_dataset
start_to_parse_the_file
consider_displaying_the_dataset_to_the_user
end
|
#sanitize_dataset ⇒ Object
199
200
201
202
203
204
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 199
def sanitize_dataset
dataset?.gsub!(/\n\n/,"\n") if dataset?.include? "\n\n"
end
|
#set_location_to_the_roebeshellrc_file(i = '') ⇒ Object
#
set_location_to_the_roebeshellrc_file
#
104
105
106
107
108
109
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 104
def set_location_to_the_roebeshellrc_file(i = '')
i = i.first if i.is_a? Array
i = i.to_s.dup
i = DEFAULT_ROEBESHELLRC_FILE_LOCATION if i.empty?
@location_to_the_roebeshellrc_file = i
end
|
#start_to_parse_the_file ⇒ Object
#
start_to_parse_the_file
This is the method that will parse through the file and set corresponding options.
#
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 212
def start_to_parse_the_file
if File.exist? input? if @dataset.include? 'colo'
@dataset =~ /colou?rs: (.+)/ add_option_to_main_hash(:use_colours, to_boolean($1.to_s.dup))
end
if @dataset.include? 'use_irc'
@dataset =~ /use_irc: (.+)/ add_option_to_main_hash(:use_irc, to_boolean($1.to_s.dup))
end
if @dataset.include? 'which_shell'
@dataset =~ /which_shell: (.+)/ add_option_to_main_hash(:which_shell, to_boolean($1.to_s.dup))
end
end
end
|
#to_boolean(i) ⇒ Object
#
to_boolean
This method will return either true or false eventually.
#
146
147
148
149
150
151
152
153
154
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 146
def to_boolean(i)
case i
when 'true'
return true
when 'false'
return false
end
i
end
|
#try_to_assign_the_dataset(i = input?)
) ⇒ Object
#
try_to_assign_the_dataset
#
232
233
234
235
236
237
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 232
def try_to_assign_the_dataset(i = input?)
if File.exist? i @dataset = File.read(i)
sanitize_dataset
end
end
|
#use_colours? ⇒ Boolean
Also known as:
colours?
97
98
99
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 97
def use_colours?
hash?['use_colours']
end
|
#use_irc? ⇒ Boolean
242
243
244
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 242
def use_irc?
hash?['use_irc']
end
|
#which_shell? ⇒ Boolean
249
250
251
|
# File 'lib/roebe/shell/shellrc_parser/shellrc_parser.rb', line 249
def which_shell?
hash?['which_shell']
end
|