Class: Cl::Ctx

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/cl/ctx.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}) ⇒ Ctx

Returns a new instance of Ctx.



14
15
16
17
18
# File 'lib/cl/ctx.rb', line 14

def initialize(name, opts = {})
  @config = Config.new(name).to_h
  @opts = opts
  @name = name
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



12
13
14
# File 'lib/cl/ctx.rb', line 12

def config
  @config
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/cl/ctx.rb', line 12

def name
  @name
end

#optsObject

Returns the value of attribute opts.



12
13
14
# File 'lib/cl/ctx.rb', line 12

def opts
  @opts
end

Instance Method Details

#abort(error, *strs) ⇒ Object



24
25
26
# File 'lib/cl/ctx.rb', line 24

def abort(error, *strs)
  abort? ? ui.abort(error, *strs) : raise(error)
end

#abort?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cl/ctx.rb', line 28

def abort?
  !opts[:abort].is_a?(FalseClass)
end

#test?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/cl/ctx.rb', line 32

def test?
  ENV['ENV'] == 'test'
end

#uiObject



20
21
22
# File 'lib/cl/ctx.rb', line 20

def ui
  @ui ||= opts[:ui] || Ui.new(self, opts)
end