Class: S3AssetDeploy::RemoteAssetCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/s3_asset_deploy/remote_asset_collector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket_name, s3_client_options: {}, remove_fingerprint: nil) ⇒ RemoteAssetCollector

Returns a new instance of RemoteAssetCollector.



10
11
12
13
14
15
16
17
# File 'lib/s3_asset_deploy/remote_asset_collector.rb', line 10

def initialize(bucket_name, s3_client_options: {}, remove_fingerprint: nil)
  @bucket_name = bucket_name
  @remove_fingerprint = remove_fingerprint
  @s3_client_options = {
    region: "us-east-1",
    logger: @logger
  }.merge(s3_client_options)
end

Instance Attribute Details

#bucket_nameObject (readonly)

Returns the value of attribute bucket_name.



8
9
10
# File 'lib/s3_asset_deploy/remote_asset_collector.rb', line 8

def bucket_name
  @bucket_name
end

Instance Method Details

#asset_pathsObject



40
41
42
# File 'lib/s3_asset_deploy/remote_asset_collector.rb', line 40

def asset_paths
  assets.map(&:path)
end

#assetsObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/s3_asset_deploy/remote_asset_collector.rb', line 23

def assets
  @assets ||= s3.list_objects_v2(bucket: bucket_name).each_with_object([]) do |response, array|
    remote_assets = response
      .contents
      .reject { |obj| obj.key == S3AssetDeploy::RemovalManifest::PATH }
      .map do |obj|
        S3AssetDeploy::RemoteAsset.new(obj, remove_fingerprint: @remove_fingerprint)
      end

    array.concat(remote_assets)
  end
end

#clear_cacheObject



36
37
38
# File 'lib/s3_asset_deploy/remote_asset_collector.rb', line 36

def clear_cache
  @assets = nil
end

#grouped_assetsObject



44
45
46
# File 'lib/s3_asset_deploy/remote_asset_collector.rb', line 44

def grouped_assets
  assets.group_by(&:original_path)
end

#inspectObject



52
53
54
# File 'lib/s3_asset_deploy/remote_asset_collector.rb', line 52

def inspect
  to_s
end

#s3Object



19
20
21
# File 'lib/s3_asset_deploy/remote_asset_collector.rb', line 19

def s3
  @s3 ||= Aws::S3::Client.new(@s3_client_options)
end

#to_sObject



48
49
50
# File 'lib/s3_asset_deploy/remote_asset_collector.rb', line 48

def to_s
  "#<#{self.class.name}:#{"0x0000%x" % (object_id << 1)} @bucket_name='#{bucket_name}'>"
end