Module: Middleman::S3Metadata

Defined in:
lib/middleman/s3_metadata/version.rb,
lib/middleman/s3_metadata/extension.rb

Defined Under Namespace

Modules: Helpers Classes: Options

Constant Summary collapse

VERSION =
'0.1.3'

Class Method Summary collapse

Class Method Details

.bucketObject



85
86
87
# File 'lib/middleman/s3_metadata/extension.rb', line 85

def bucket
  @bucket ||= connection.directories.get(options.bucket)
end

.connectionObject



78
79
80
81
82
83
# File 'lib/middleman/s3_metadata/extension.rb', line 78

def connection
  @connection ||= Fog::Storage.new(provider: 'AWS',
                                   aws_access_key_id: options.aws_access_key_id,
                                   aws_secret_access_key: options.aws_secret_access_key,
                                   region: options.region)
end

.generateObject



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/middleman/s3_metadata/extension.rb', line 64

def generate
  options.mappings.each do |mapping|
    if mapping.value.nil?
      puts "Unset metadata for '/#{mapping.object}' with '#{mapping.key}'"
    else
      puts "Set metadata for '/#{mapping.object}' with '#{mapping.key}' => '#{mapping.value}'"
    end
    file = s3_files.find { |i| i.key == mapping.object }
    file.reload
    file. = { mapping.key => mapping.value }
    file.save
  end
end

.optionsObject



42
43
44
# File 'lib/middleman/s3_metadata/extension.rb', line 42

def options
  @@options
end

.registered(app, options_hash = {}) {|options| ... } ⇒ Object Also known as: included

Yields:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/middleman/s3_metadata/extension.rb', line 46

def registered(app, options_hash = {}, &block)
  options = Options.new(options.hash)
  yield options if block_given?

  @@options = options

  app.send :include, Helpers

  options.public_path ||= 'build'

  app.after_configuration do |config|
    after_build do |builder|
      ::Middleman::S3Metadata.generate if options.after_build
    end
  end
end

.s3_filesObject



89
90
91
# File 'lib/middleman/s3_metadata/extension.rb', line 89

def s3_files
  @s3_files ||= bucket.files
end