Module: Lightning::Builder

Extended by:
Builder
Included in:
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 collapse

HEADER =
<<-INIT.gsub(/^\s{4}/,'')
#### This file was built by lightning. ####
#LBIN_PATH="$PWD/bin/" #only use for development
LBIN_PATH=""

lightning-reload() {
  lightning install $@
  source_file=$(lightning source_file)
  source $source_file
  echo Loaded $source_file
}
INIT

Instance Method Summary collapse

Instance Method Details

#build(args) ⇒ String

Returns Shell file string to be saved and sourced.

Parameters:

  • Function (Array)

    objects

Returns:

  • (String)

    Shell file string to be saved and sourced



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

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

#can_build?Boolean

Returns Determines if Builder can build a file for its current shell.

Returns:

  • (Boolean)

    Determines if Builder can build a file for its current shell



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

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

#runString

Returns Builds shell file.

Returns:

  • (String)

    Builds shell file



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

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

#shellString

Returns Current shell, defaults to ‘bash’.

Returns:

  • (String)

    Current shell, defaults to ‘bash’



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

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