Class: Expressir::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/expressir/commands/base.rb

Direct Known Subclasses

Benchmark, BenchmarkCache, Clean, Coverage, Format, Validate, Version

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



6
7
8
# File 'lib/expressir/commands/base.rb', line 6

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/expressir/commands/base.rb', line 4

def options
  @options
end

Instance Method Details

#exit_with_error(message, exit_code = 1) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/expressir/commands/base.rb', line 20

def exit_with_error(message, exit_code = 1)
  say message
  # In test mode, raise an exception instead of exiting
  # This makes it easier to test error cases
  if defined?(@test_mode) && @test_mode
    raise message # Just raise the message as an exception
  else
    exit exit_code
  end
end

#say(message) ⇒ Object

Common utilities that all commands might need



11
12
13
14
15
16
17
18
# File 'lib/expressir/commands/base.rb', line 11

def say(message)
  # Use instance variable for testability - if output is set, use it
  if defined?(@output) && @output
    @output.puts(message)
  else
    puts(message)
  end
end