Class: FaaStRuby::Local::StaticFile
- Inherits:
-
Object
- Object
- FaaStRuby::Local::StaticFile
- Includes:
- Logger
- Defined in:
- lib/faastruby/local/static_files/static_file.rb
Class Method Summary collapse
Instance Method Summary collapse
- #deploy ⇒ Object
-
#initialize(full_path:, relative_path:, filename:, dirname:) ⇒ StaticFile
constructor
A new instance of StaticFile.
- #remove_from_workspace ⇒ Object
Methods included from Logger
Constructor Details
#initialize(full_path:, relative_path:, filename:, dirname:) ⇒ StaticFile
Returns a new instance of StaticFile.
19 20 21 22 23 24 25 26 |
# File 'lib/faastruby/local/static_files/static_file.rb', line 19 def initialize(full_path:, relative_path:, filename:, dirname:) @full_path = full_path @relative_path = relative_path @filename = filename @dirname = dirname @config = YAML.load(File.read("#{Local.public_dir}/faastruby.yml")) @before_build = @config['before_build'] || [] end |
Class Method Details
.full_sync ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/faastruby/local/static_files/static_file.rb', line 6 def self.full_sync cmd = "faastruby deploy-to '#{Local.workspace}' -f '#{Local.public_dir}'" output, status = Open3.capture2e(cmd) String.disable_colorization = true if status.exitstatus == 0 output.split("\n").each {|o| puts "#{Time.now} | #{o}" unless o == '---'} puts '---' else STDERR.puts output end String.disable_colorization = false end |
Instance Method Details
#deploy ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/faastruby/local/static_files/static_file.rb', line 28 def deploy path = "public/#{@relative_path}" cmd = "faastruby cp '#{path}' '#{Local.workspace}:/#{@relative_path}'" puts "Running: #{cmd}" i, oe, thr = Open3.popen2(cmd) i.close STDOUT.puts "#{Time.now} | * [#{path}] Uploading file to workspace '#{Local.workspace}'" oe.each_line do |line| next if line.chomp == '' || line.chomp == '---' STDOUT.puts "#{Time.now} | #{line}" STDOUT.puts "---" end thr.join oe.close status = thr.value puts "* [#{path}] Error uploading static file '#{path}' to cloud workspace '#{Local.workspace}':" if status.exitstatus != 0 end |
#remove_from_workspace ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/faastruby/local/static_files/static_file.rb', line 46 def remove_from_workspace path = "public/#{@relative_path}" cmd = "faastruby rm '#{Local.workspace}:/#{@relative_path}'" puts "Running: #{cmd}" output, status = Open3.capture2e(cmd) String.disable_colorization = true if status.exitstatus == 0 output.split("\n").each {|o| puts o unless o == '---'} else puts "* [#{path}] Error removing static file '#{path}' from cloud workspace '#{Local.workspace}':" STDERR.puts output end String.disable_colorization = false end |