Class: Asgard::Base

Inherits:
Thor
  • Object
show all
Extended by:
DependencyGraph, Registry, TaskDSL
Includes:
Dispatch, Shell
Defined in:
lib/asgard/base.rb,
lib/asgard/base/dispatch.rb,
lib/asgard/base/registry.rb,
lib/asgard/base/task_dsl.rb,
lib/asgard/base/dependency_graph.rb

Direct Known Subclasses

Tasks

Defined Under Namespace

Modules: DependencyGraph, Dispatch, Registry, TaskDSL

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Registry

_method_log, inherited, subclasses

Methods included from DependencyGraph

_deps, depends_on, validate_deps!

Methods included from TaskDSL

default_task, desc, dotenv, helper, no_negate

Methods included from Dispatch

#dep_result, #dep_results, included, #invoke_command

Methods included from Shell

#sh, #shebang

Class Method Details



26
27
28
29
# File 'lib/asgard/base.rb', line 26

def footer(text = nil)
  return @_footer if text.nil?
  (@_footer ||= []).unshift(text)
end

.header(text = nil) ⇒ Object



21
22
23
24
# File 'lib/asgard/base.rb', line 21

def header(text = nil)
  return @_header if text.nil?
  (@_header ||= []) << text
end

.method_added(method_name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/asgard/base.rb', line 31

def method_added(method_name)
  name           = method_name.to_s
  private_method = name.start_with?("_")

  unless private_method
    loc = instance_method(method_name).source_location
    _method_log[method_name] << loc if loc
  end

  if @_pending_single_desc && !no_commands?
    pending_desc = @_pending_single_desc
    pending_opts = @_pending_single_desc_opts || {}
    @_pending_single_desc      = nil
    @_pending_single_desc_opts = nil
    desc(name, pending_desc, pending_opts)
  end

  return super unless @usage

  pending = Array(@_pending_deps).dup
  @_pending_deps = []

  return super if pending.empty?
  return super if private_method

  _deps[method_name.to_sym] = _normalize_pending_deps(pending)
  super
end

Instance Method Details

#help(command = nil, subcommand = false) ⇒ Object

rubocop:disable Style/OptionalBooleanParameter



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/asgard/base.rb', line 61

def help(command = nil, subcommand = false) # rubocop:disable Style/OptionalBooleanParameter
  klass       = self.class
  top_level   = command.nil?
  header_text = klass.header
  footer_text = klass.footer

  say header_text.join("\n\n") if header_text && top_level
  say "\n"
  super
  say footer_text.join("\n\n") if footer_text && top_level
end

#treeObject



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/asgard/base.rb', line 73

def tree
  klass       = self.class
  header_text = klass.header
  footer_text = klass.footer

  say header_text.join("\n\n") if header_text
  say "\n"
  super
  say "\n"
  say footer_text.join("\n\n") if footer_text
end