Module: Lightning::Builder
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
-
#build(args) ⇒ String
Shell file string to be saved and sourced.
-
#can_build? ⇒ Boolean
Determines if Builder can build a file for its current shell.
-
#run ⇒ String
Builds shell file.
-
#shell ⇒ String
Current shell, defaults to ‘bash’.
Instance Method Details
#build(args) ⇒ String
Returns 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.
23 24 25 |
# File 'lib/lightning/builder.rb', line 23 def can_build? respond_to? "#{shell}_builder" end |
#run ⇒ String
Returns 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 |