Class: FaaStRuby::Command::Function::Build
Class Method Summary
collapse
Instance Method Summary
collapse
#load_yaml
Methods inherited from BaseCommand
#has_user_logged_in?, #help, #load_credentials, #load_yaml, #say, spin, #spin, #write_file
Constructor Details
#initialize(args) ⇒ Build
Returns a new instance of Build.
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/faastruby/cli/commands/function/build.rb', line 15
def initialize(args)
@args = args
load_yaml
@yaml_config['before_build'] ||= []
@function_name = @yaml_config['name']
@abort_when_tests_fail = @yaml_config['abort_build_when_tests_fail']
parse_options
@options['source'] ||= '.'
@package_file = Tempfile.new('package')
@options['output_file'] ||= @package_file.path
end
|
Class Method Details
.build(source, output_file, function_name, quiet = false, exclude: []) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/faastruby/cli/commands/function/build.rb', line 7
def self.build(source, output_file, function_name, quiet = false, exclude: [])
FaaStRuby::Package.new(source, output_file, exclude: exclude).build
puts "+ f #{output_file}".green unless quiet
end
|
.help ⇒ Object
50
51
52
|
# File 'lib/faastruby/cli/commands/function/build.rb', line 50
def self.help
"build".light_cyan + " [-s, --source SOURCE_DIR] [-o, --output-file OUTPUT_FILE]"
end
|
Instance Method Details
#crystal_runtime? ⇒ Boolean
31
32
33
|
# File 'lib/faastruby/cli/commands/function/build.rb', line 31
def crystal_runtime?
@yaml_config['runtime'].match(/^crystal/)
end
|
#ruby_runtime? ⇒ Boolean
27
28
29
|
# File 'lib/faastruby/cli/commands/function/build.rb', line 27
def ruby_runtime?
@yaml_config['runtime'].nil? || @yaml_config['runtime'].match(/^ruby/)
end
|
#run ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/faastruby/cli/commands/function/build.rb', line 35
def run
if ruby_runtime?
FaaStRuby::CLI.error('Please fix the problems above and try again') unless bundle_install
end
if crystal_runtime?
FaaStRuby::CLI.error('Please fix the problems above and try again') unless shards_install
end
tests_passed = run_tests
FaaStRuby::CLI.error("Build aborted because tests failed and you have 'abort_build_when_tests_fail: true' in 'faastruby.yml'") unless tests_passed || !@abort_when_tests_fail
puts "[#{@function_name}] Warning: Ignoring failed tests because you have 'abort_build_when_tests_fail: false' in 'faastruby.yml'".yellow if !tests_passed && !@abort_when_tests_fail
build(@options['source'], @options['output_file'])
@package_file.close
@package_file.unlink
end
|
#usage ⇒ Object
54
55
56
|
# File 'lib/faastruby/cli/commands/function/build.rb', line 54
def usage
"Usage: faastruby #{self.class.help}"
end
|