Class: ClusterFuck::Reader

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

Constant Summary collapse

LOCAL_OVERRIDE_DIR =
"cluster-fuck"
SHARED_ENV =
"shared"

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 = {}) ⇒ Reader

Returns a new instance of Reader.



10
11
12
13
14
# File 'lib/cluster-fuck/reader.rb', line 10

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

Instance Attribute Details

#amicus_envObject (readonly)

Returns the value of attribute amicus_env.



9
10
11
# File 'lib/cluster-fuck/reader.rb', line 9

def amicus_env
  @amicus_env
end

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/cluster-fuck/reader.rb', line 9

def key
  @key
end

#version_countObject (readonly)

Returns the value of attribute version_count.



9
10
11
# File 'lib/cluster-fuck/reader.rb', line 9

def version_count
  @version_count
end

Instance Method Details

#has_local_override?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/cluster-fuck/reader.rb', line 33

def has_local_override?
  File.exists?(local_override_path)
end

#local_override_pathObject



37
38
39
# File 'lib/cluster-fuck/reader.rb', line 37

def local_override_path
  File.join(LOCAL_OVERRIDE_DIR, full_s3_path(key))
end

#read(opts = {}) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/cluster-fuck/reader.rb', line 24

def read(opts = {})
  set_amicus_env_to_shared_unless_key_found!
  yaml = data_for_key(opts)
  if yaml
    @version_count = stored_object.versions.count unless has_local_override?
    Configuration.from_yaml(yaml)
  end
end

#set_amicus_env_to_shared_unless_key_found!Object



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

def set_amicus_env_to_shared_unless_key_found!
  unless has_local_override? or stored_object.exists?
    original_amicus_env = @amicus_env
    @amicus_env = SHARED_ENV
    raise KeyDoesNotExistError, "there was no #{key} in either #{original_amicus_env} or #{SHARED_ENV}" unless stored_object(true).exists?
  end
end