Class: HammerCLI::Subcommand::LazyDefinition

Inherits:
Definition
  • Object
show all
Defined in:
lib/hammer_cli/subcommand.rb

Instance Attribute Summary

Attributes inherited from Definition

#warning

Instance Method Summary collapse

Methods inherited from Definition

#help, #hidden?

Constructor Details

#initialize(names, description, subcommand_class_name, path, options = {}) ⇒ LazyDefinition

Returns a new instance of LazyDefinition.



37
38
39
40
41
# File 'lib/hammer_cli/subcommand.rb', line 37

def initialize(names, description, subcommand_class_name, path, options = {})
  super(names, description, subcommand_class_name, options)
  @loaded = false
  @path = path
end

Instance Method Details

#loaded?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/hammer_cli/subcommand.rb', line 43

def loaded?
  @loaded
end

#subcommand_classObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/hammer_cli/subcommand.rb', line 47

def subcommand_class
  unless @loaded
    require @path
    @loaded = true
    @constantized_class = @subcommand_class.constantize
  end
  @warning ||= @constantized_class.warning
  warn(@warning) if @warning
  @constantized_class
end