Class: StartupTime::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/startup_time/options.rb

Overview

StartupTime::Options - a struct-like interface to the app options set or overridden on the command line

Constant Summary collapse

BUILD_DIR =
EnvPaths.get('startup-time', suffix: false).cache
DEFAULT_DURATION =
10
MINIMUM_DURATION =
2
Spec =
Value.new(:type, :value)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Options

Returns a new instance of Options.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/startup_time/options.rb', line 21

def initialize(args)
  @action = :benchmark
  @build_dir = BUILD_DIR
  @duration = DEFAULT_DURATION
  @format = :default
  @parser = nil
  @rounds = nil
  @spec = nil
  @verbosity = :default

  parse! args
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



17
18
19
# File 'lib/startup_time/options.rb', line 17

def action
  @action
end

#build_dirObject (readonly)

Returns the value of attribute build_dir.



17
18
19
# File 'lib/startup_time/options.rb', line 17

def build_dir
  @build_dir
end

#formatObject (readonly)

Returns the value of attribute format.



17
18
19
# File 'lib/startup_time/options.rb', line 17

def format
  @format
end

#roundsObject (readonly)

Returns the value of attribute rounds.



17
18
19
# File 'lib/startup_time/options.rb', line 17

def rounds
  @rounds
end

#verbosityObject (readonly)

Returns the value of attribute verbosity.



17
18
19
# File 'lib/startup_time/options.rb', line 17

def verbosity
  @verbosity
end

Instance Method Details

#specObject



34
35
36
37
38
39
40
# File 'lib/startup_time/options.rb', line 34

def spec
  @spec ||= if @rounds
    Spec.with(type: :count, value: @rounds)
  else
    Spec.with(type: :duration, value: @duration)
  end
end

#usageObject

the usage message (string) generated by the option parser for this tool



43
44
45
# File 'lib/startup_time/options.rb', line 43

def usage
  @parser.to_s
end