Class: ClusterFuck::Writer

Inherits:
Object
  • Object
show all
Includes:
S3Methods
Defined in:
lib/cluster-fuck/writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from S3Methods

#all_files, #bucket, #credentials, #full_s3_path, #s3, #s3_object

Constructor Details

#initialize(key, opts = {}) ⇒ Writer

Returns a new instance of Writer.



6
7
8
9
# File 'lib/cluster-fuck/writer.rb', line 6

def initialize(key, opts = {})
  @key = key
  @amicus_env = opts[:amicus_env] || ClusterFuck.amicus_env
end

Instance Attribute Details

#amicus_envObject (readonly)

Returns the value of attribute amicus_env.



5
6
7
# File 'lib/cluster-fuck/writer.rb', line 5

def amicus_env
  @amicus_env
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/cluster-fuck/writer.rb', line 5

def key
  @key
end

Instance Method Details

#raise_unless_version_count_is_good(version_count) ⇒ Object



18
19
20
21
22
# File 'lib/cluster-fuck/writer.rb', line 18

def raise_unless_version_count_is_good(version_count)
  if version_count and stored_object.versions.count > version_count
    raise ConflictError, "File #{key} changed underneath you, version_count expected to be #{version_count} but was #{stored_object.versions.count}"
  end
end

#set(val, version_count = nil) ⇒ Object

todo, thread safety and process safety please



12
13
14
15
16
# File 'lib/cluster-fuck/writer.rb', line 12

def set(val, version_count = nil)
  raise_unless_version_count_is_good(version_count)
  stored_object.write(val.to_yaml)
  raise_unless_version_count_is_good(version_count + 1) if version_count
end

#stored_objectObject



24
25
26
# File 'lib/cluster-fuck/writer.rb', line 24

def stored_object
  @stored_object ||= s3_object(key)
end