Class: Canistor::Storage::Bucket::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/canistor/storage/bucket/settings.rb

Overview

Stores settings for the bucket.

+allow_access_keys+: Allow full access to the bucket using these
access keys.
+replicate_to+: Replicate all updates to the bucket to this bucket.
+versioned+: Use versioning on the bucket.

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Settings

Returns a new instance of Settings.



13
14
15
16
# File 'lib/canistor/storage/bucket/settings.rb', line 13

def initialize(settings = {})
  clear
  update(settings)
end

Instance Method Details

#access_keysObject



31
32
33
# File 'lib/canistor/storage/bucket/settings.rb', line 31

def access_keys
  @access_keys
end

#allow_access_keys(access_key_ids) ⇒ Object



43
44
45
# File 'lib/canistor/storage/bucket/settings.rb', line 43

def allow_access_keys(access_key_ids)
  @access_keys.merge(access_key_ids)
end

#clearObject



75
76
77
78
79
# File 'lib/canistor/storage/bucket/settings.rb', line 75

def clear
  @access_keys = Set.new
  @replicates_to = []
  @versioned = false
end

#replicate_to(replicates_to) ⇒ Object



51
52
53
# File 'lib/canistor/storage/bucket/settings.rb', line 51

def replicate_to(replicates_to)
  @replicates_to = replicates_to
end

#replicate_to_bucketsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/canistor/storage/bucket/settings.rb', line 55

def replicate_to_buckets
  return [] unless replicated?
  @replicates_to.map do |location|
    if bucket = Canistor.store.dig(*location.split(':'))
      bucket
    else
      raise(
        Canistor::ConfigurationError,
        "Can't locate bucket `#{location}' when trying to replicate " \
        "object. Please make sure the replication location is in the " \
        "form of region:bucket and configured in Canistor."
      )
    end
  end
end

#replicated?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/canistor/storage/bucket/settings.rb', line 47

def replicated?
  @replicates_to && !@replicates_to.empty?
end

#replicates_toObject



35
36
37
# File 'lib/canistor/storage/bucket/settings.rb', line 35

def replicates_to
  @replicates_to
end

#update(settings) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/canistor/storage/bucket/settings.rb', line 18

def update(settings)
  case settings
  # Old style setup allowed settings to be an array of allowed access
  # keys.
  when Set, Array
    allow_access_keys(settings)
  else
    settings.each do |name, value|
      public_send("#{name}", value)
    end
  end
end

#versioned(versioned) ⇒ Object



71
72
73
# File 'lib/canistor/storage/bucket/settings.rb', line 71

def versioned(versioned)
  @versioned = versioned
end

#versioned?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/canistor/storage/bucket/settings.rb', line 39

def versioned?
  !!@versioned
end