Module: R2do::Utility

Included in:
App
Defined in:
lib/r2do/utility.rb

Class Method Summary collapse

Class Method Details

.calculate_path(file_name) ⇒ String

Calculates the path location for the data file.

Parameters:

  • file_name (String)

    the name of the file to load.

Returns:

  • (String)

    the full destination path including the filename.



55
56
57
58
# 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) ⇒ State

Loads the data file and deserializes the State.

Parameters:

  • file_name (String)

    the name of the file to load.

Returns:

  • (State)

    the application 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.

Parameters:

  • file_name (String)

    the name of the file to save.

  • the (State)

    application state to save.



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

Parameters:

  • args (Array)

    the list of args the user passed the application



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

.show_version(args) ⇒ void

This method returns an undefined value.

Show the version number of the application

Parameters:

  • args (Array)

    the list of args the user passed the application



82
83
84
# File 'lib/r2do/utility.rb', line 82

def show_version(args)
  UI.status(R2do::VERSION)
end