Class: ClusterFsck::Reader

Inherits:
Object
  • Object
show all
Includes:
S3Methods
Defined in:
lib/clusterfsck/reader.rb

Constant Summary collapse

LOCAL_OVERRIDE_DIR =
"clusterfsck"
SHARED_ENV =
"shared"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from S3Methods

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

Constructor Details

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

Returns a new instance of Reader.



10
11
12
13
14
# File 'lib/clusterfsck/reader.rb', line 10

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

Instance Attribute Details

#cluster_fsck_envObject (readonly)

Returns the value of attribute cluster_fsck_env.



9
10
11
# File 'lib/clusterfsck/reader.rb', line 9

def cluster_fsck_env
  @cluster_fsck_env
end

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/clusterfsck/reader.rb', line 9

def key
  @key
end

#version_countObject (readonly)

Returns the value of attribute version_count.



9
10
11
# File 'lib/clusterfsck/reader.rb', line 9

def version_count
  @version_count
end

Instance Method Details

#has_local_override?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/clusterfsck/reader.rb', line 33

def has_local_override?
  File.exists?(local_override_path)
end

#local_override_pathObject



37
38
39
# File 'lib/clusterfsck/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/clusterfsck/reader.rb', line 24

def read(opts = {})
  set_cluster_fsck_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_cluster_fsck_env_to_shared_unless_key_found!Object



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

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