Class: Highlander::Publisher::Component
- Inherits:
-
Object
- Object
- Highlander::Publisher::Component
- Defined in:
- lib/highlander.publisher.rb
Instance Method Summary collapse
-
#initialize(component, cleanup) ⇒ Component
constructor
A new instance of Component.
- #publishComponent ⇒ Object
- #publishFiles(file_list) ⇒ Object
Constructor Details
#initialize(component, cleanup) ⇒ Component
Returns a new instance of Component.
10 11 12 13 |
# File 'lib/highlander.publisher.rb', line 10 def initialize(component, cleanup) @component = component @cleanup_destination = cleanup end |
Instance Method Details
#publishComponent ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/highlander.publisher.rb', line 15 def publishComponent bucket = @component.highlander_dsl.distribution_bucket prefix = @component.highlander_dsl.distribution_prefix version = @component.highlander_dsl.version s3 = Aws::S3::Client.new({ region: s3_bucket_region(bucket) }) existing_objects = s3.list_objects_v2({bucket: bucket, prefix: "#{prefix}/#{@component.name}/#{version}"}) existing_objects.contents.each do |s3obj| print "Deleting previously published #{s3obj.key} ..." s3.delete_object(bucket: bucket, key: s3obj.key) print " [OK] \n" end if @cleanup_destination @component.component_files.each do |file_path| File.open(file_path, 'rb') do |file| file_path = file_path.gsub(@component.component_dir, '')[1..-1] s3_key = "#{prefix}/#{@component.name}/#{version}/#{file_path}" print "Publish component file #{file_path} to s3://#{bucket}/#{s3_key} ... " s3.put_object(bucket: bucket, key: s3_key, body: file) print " [OK] \n" end end end |
#publishFiles(file_list) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/highlander.publisher.rb', line 40 def publishFiles(file_list) bucket = @component.highlander_dsl.distribution_bucket prefix = @component.highlander_dsl.distribution_prefix version = @component.highlander_dsl.version s3 = Aws::S3::Client.new({ region: s3_bucket_region(bucket) }) s3.list_objects_v2(bucket: bucket, prefix: "#{prefix}/#{version}").contents.each do |s3obj| print "\nDeleting previously published #{s3obj.key} ..." s3.delete_object(bucket: bucket, key: s3obj.key) print ' [OK]' end if @cleanup_destination file_list.each do |file| file_name = File.basename file s3_key = "#{prefix}/#{version}/#{file_name}" print "\nPublishing #{file} to s3://#{bucket}/#{s3_key} ..." s3.put_object({ body: File.read(file), bucket: bucket, key: s3_key }) print ' [OK] ' end print "\n" end |