Class: Brandish::Application Private

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
lib/brandish/application.rb,
lib/brandish/application/bench_command.rb,
lib/brandish/application/build_command.rb,
lib/brandish/application/serve_command.rb,
lib/brandish/application/initialize_command.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The command line interface for Brandish.

Defined Under Namespace

Classes: BenchCommand, BuildCommand, InitializeCommand, ServeCommand

Constant Summary collapse

PROGRESS_OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Options that are passed to the progress method provided by Commander. This makes it look "nice."

Returns:

  • ({::Symbol => ::String})
{
  title: "   Building...", progress_str: "#", incomplete_str: " ",
  format: ":title <:progress_bar> :percent_complete%",
  complete_message: "   Build complete!"
}.freeze
PROGRESS_WIDTH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The width of all of the set text items in the progress bar. This is used to dynamically determine the with of the progress bar later on.

Returns:

  • (::Numeric)
"   Building... <  > 000%  ".length

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#config_file::String (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The name of the configure file. This should be "brandish.config.rb", but may change in the future (maybe Brandishfile?).

Returns:

  • (::String)


24
25
26
# File 'lib/brandish/application.rb', line 24

def config_file
  @config_file
end

#directory::String (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The executing directory for the application. This is provided with the global option -d. Using this should be the same as using cd and executing the command.

Returns:

  • (::String)


31
32
33
# File 'lib/brandish/application.rb', line 31

def directory
  @directory
end

Class Method Details

.callvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Defines and runs the command line interface.

See Also:



37
38
39
# File 'lib/brandish/application.rb', line 37

def self.call
  new.call
end

Instance Method Details

#callvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Defines and runs the command line interface.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/brandish/application.rb', line 51

def call
  program_information
  configure_global_option
  directory_global_option
  command(:initialize) { |c| InitializeCommand.define(self, c) }
  command(:bench) { |c| BenchCommand.define(self, c) }
  command(:build) { |c| BuildCommand.define(self, c) }
  command(:serve) { |c| ServeCommand.define(self, c) }
  alias_command(:init, :initialize)
  default_command(:build)
  run!
end

#config_file_path::Pathname

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The path to the configuration file. This is used for #load_configuration_file!.

Returns:

  • (::Pathname)


134
135
136
# File 'lib/brandish/application.rb', line 134

def config_file_path
  @directory / @config_file
end

#configure_global_optionvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Defines the config global option. This sets #config_file to its default file, and defines an option that can set it.



81
82
83
84
# File 'lib/brandish/application.rb', line 81

def configure_global_option
  @config_file = "brandish.config.rb"
  global_option("--config FILE") { |f| @config_file = f }
end

#directory_global_optionvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Defines the directory global option. This sets #directory to its default value, and defines an option that can set it.



90
91
92
93
94
95
# File 'lib/brandish/application.rb', line 90

def directory_global_option
  @directory = Pathname.new(Dir.pwd)
  global_option("--directory PATH") do |path|
    @directory = Pathname.new(path).expand_path(Dir.pwd)
  end
end

#load_configuration_fileConfigure

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

If the configuration isn't already loaded, load it; otherwise, just return the already loaded version of the configuration file.

Returns:



142
143
144
# File 'lib/brandish/application.rb', line 142

def load_configuration_file
  Brandish.configuration || load_configuration_file!
end

#load_configuration_file!Configure

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Forces the configuration file to be loaded, even if it already was; this first resets the configuration using Brandish.reset_configuration, then it loads the #config_file_path. If no configuration was provided, it fails; if it didn't load properly, it fails.

Returns:

Raises:

  • (RuntimeError)

    If no configuration was provided, or if it didn't load properly.



154
155
156
157
158
159
160
161
# File 'lib/brandish/application.rb', line 154

def load_configuration_file!
  Brandish.reset_configuration
  load config_file_path.to_s
  fail "No configuration provided" unless Brandish.configuration
  Brandish.configuration
rescue LoadError
  fail "No configuration provided"
end

#program_informationvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

The program information. This is for use with Commander.



67
68
69
70
71
72
73
74
75
# File 'lib/brandish/application.rb', line 67

def program_information
  program :name, "Brandish"
  program :version, Brandish::VERSION
  program :help_formatter, :compact
  program :help_paging, false
  program :description, "A multi-format document generator."
  program :help, "Author", "Jeremy Rodi <[email protected]>"
  program :help, "License", "MIT License Copyright (c) 2017 Jeremy Rodi"
end

#progress(array) {|item| ... } ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Creates a progress bar on the terminal based off of the given array. This mostly passes everything on to the progress method provided by Commander, but with a few options added.

Parameters:

  • array (::Array)

    The array of items that are being processed.

Yields:

  • (item)

    Once for every item in the array. Once the block ends, the progress bar increments.

Yield Parameters:

  • item (::Object)

    One of the items in the array.



122
123
124
125
126
127
128
# File 'lib/brandish/application.rb', line 122

def progress(array, &block)
  # rubocop:disable Style/GlobalVars
  width = $terminal.terminal_size[0] - PROGRESS_WIDTH
  # rubocop:enable Style/GlobalVars
  options = PROGRESS_OPTIONS.merge(width: width)
  super(array, options, &block)
end