Module: Lightning::Builder

Extends:
Lightning::Builder
Defined in:
lib/lightning/builder.rb

Overview

Builds shell file ~/.lightning/functions.sh from the config file. This file is built and sourced into a user’s shell using `lightning-reload`. Currently supports bash and zsh shells. Defaults to building for bash.

Constant Summary

Instance Method Summary

Instance Method Details

- (String) build(args)

Shell file string to be saved and sourced

Parameters:

  • (Array) Function — objects

Returns:

  • (String) — Shell file string to be saved and sourced

45
46
47
# File 'lib/lightning/builder.rb', line 45

def build(args)
  HEADER + "\n\n" + send("#{shell}_builder", *[args])
end

- (Boolean) can_build?

Determines if Builder can build a file for its current shell

Returns:

  • (Boolean) — Determines if Builder can build a file for its current shell

24
25
26
# File 'lib/lightning/builder.rb', line 24

def can_build?
  respond_to? "#{shell}_builder"
end

- (String) run

Builds shell file

Returns:

  • (String) — Builds shell file

34
35
36
37
38
39
40
41
# File 'lib/lightning/builder.rb', line 34

def run
  return puts("No builder exists for #{Builder.shell} shell") unless Builder.can_build?
  functions = Lightning.functions.values
  check_for_existing_commands(functions)
  output = build(functions)
  File.open(Lightning.config.source_file, 'w') {|f| f.write(output) }
  output
end

- (String) shell

Current shell, defaults to ‘bash’

Returns:

  • (String) — Current shell, defaults to ‘bash’

29
30
31
# File 'lib/lightning/builder.rb', line 29

def shell
  Lightning.config[:shell] || 'bash'
end