Class: Brandish::Application::BenchCommand Private

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
lib/brandish/application/bench_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 bench command. This builds the project in the set directory, and benchmarks. This is for debugging.

Constant Summary collapse

DEFAULTS =

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 default options for the build command.

Returns:

  • ({::Symbol => ::Object})
{ only: :all, path: "profile", name: "default" }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application, options) ⇒ BenchCommand

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.

Initialize the build command.



45
46
47
48
# File 'lib/brandish/application/bench_command.rb', line 45

def initialize(application, options)
  @application = application
  @options = DEFAULTS.merge(options)
end

Class Method Details

.call(application, options) ⇒ 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.

Performs the build command. This initializes the command, and calls #call.

Parameters:

  • application (Application)

    The application.

  • options ({::Symbol => ::Object})

    The options for the command.



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

def self.call(application, options)
  new(application, options).call
end

.define(application, command) ⇒ 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.

Defines the command on the given application. This sets the important data information for the command, for use for the help output.

Parameters:

  • application (Application)
  • command (Commander::Command)


17
18
19
20
21
22
23
24
# File 'lib/brandish/application/bench_command.rb', line 17

def self.define(application, command)
  command.syntax = "brandish build"
  command.option "-o", "--only NAMES", [::String]
  command.option "-p", "--path PATH", ::String
  command.option "-n", "--name NAME", ::String

  command.action { |_, o| call(application, o.__hash__) }
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.

Performs the build. First, it loads the configuration file for the build. Then, it performs the build, calling Configure#build with the :only filter provided by the options. This uses a Commander native called progress to make it look nice on the output.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/brandish/application/bench_command.rb', line 56

def call
  require "ruby-prof"
  require "benchmark"

  @configure = @application.load_configuration_file
  @path = ::Pathname.new(@options[:path]).expand_path(Dir.pwd)
  @path.mkpath
  say "=> Beginning build..."

  result = nil
  time = Benchmark.measure { result = RubyProf.profile { perform_build } }
  say "-> Build ended, time: #{time}"
  say "=> Outputting profile..."

  result.eliminate_methods!(method_eleminations)
  output_profile(result)
end