module R2do::Utility
Public Instance Methods
calculate_path(file_name)
click to toggle source
Calculates the path location for the data file.
@param [String] file_name the name of the file to load. @return [String] the full destination path including the filename.
# File lib/r2do/utility.rb, line 55 def calculate_path(file_name) data_path = File.expand_path("~/") file_path = File.join(data_path, file_name) end
load_state(file_name)
click to toggle source
Loads the data file and deserializes the State
.
@param [String] file_name the name of the file to load. @return [State] the application State
.
# File lib/r2do/utility.rb, line 25 def load_state(file_name) file_path = calculate_path(file_name) if File.exists?(file_path) file = File.open(file_path, "rb") state = YAML::load(file.read) else state = State.new end state end
save_state(file_name, state)
click to toggle source
Saves the data file and serializes the State
.
@param [String] file_name the name of the file to save. @param [State] the application state to save. @return [void]
# File lib/r2do/utility.rb, line 43 def save_state(file_name, state) file_path = calculate_path(file_name) file = File.new(file_path, 'w') file.write(YAML.dump(state)) file.close() end
show_help(args)
click to toggle source
Show the help command
@param [Array] args the list of args the user passed the application @return [void]
# File lib/r2do/utility.rb, line 64 def show_help(args) UI.status("Usage:") UI.status(" r2do <command> [<args>] [options]") UI.new_line() UI.status("Commands:") @commands.each do |value| UI.status(" %s" % value.to_s()) end UI.new_line() UI.status("See 'r2do help <command>' for more information on a specific command.") end
show_version(args)
click to toggle source
Show the version number of the application
@param [Array] args the list of args the user passed the application @return [void]
# File lib/r2do/utility.rb, line 82 def show_version(args) UI.status(R2do::VERSION) end