Module: R2do::Utility
- Included in:
- App
- Defined in:
- lib/r2do/utility.rb
Class Method Summary collapse
-
.calculate_path(file_name) ⇒ String
Calculates the path location for the data file.
-
.load_state(file_name) ⇒ State
Loads the data file and deserializes the State.
-
.save_state(file_name, state) ⇒ void
Saves the data file and serializes the State.
-
.show_help(args) ⇒ void
Show the help command.
-
.show_version(args) ⇒ void
Show the version number of the application.
Class Method Details
.calculate_path(file_name) ⇒ String
Calculates the path location for the data file.
55 56 57 58 |
# File 'lib/r2do/utility.rb', line 55 def calculate_path(file_name) data_path = File.("~/") file_path = File.join(data_path, file_name) end |
.load_state(file_name) ⇒ State
Loads the data file and deserializes the State.
25 26 27 28 29 30 31 32 33 34 35 36 |
# 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) ⇒ void
This method returns an undefined value.
Saves the data file and serializes the State.
43 44 45 46 47 48 49 |
# 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) ⇒ void
This method returns an undefined value.
Show the help command
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# 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 |