Class: Bubbles::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/bubbles/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#config_pathObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/bubbles/config.rb', line 72

def config_path
  if @config_path
    raise "Config file #{@config_path} does not exist" unless File.exist?(@config_path)
    @config_path
  elsif File.exist?(self.class.var_config) && use_default_config_locations
    self.class.var_config
  elsif File.exist?(self.class.home_config) && use_default_config_locations
    self.class.home_config
  end
end

#local_dir_metadata_file_pathObject



47
48
49
50
# File 'lib/bubbles/config.rb', line 47

def 
  err_msg = 'You need to set `local_dir_metadata_file_path`'
  @local_dir_metadata_file_path ||= config_yml.fetch('local_dir_metadata_file_path') { raise err_msg }
end

#local_dir_uploader_pathObject



52
53
54
55
56
57
58
# File 'lib/bubbles/config.rb', line 52

def local_dir_uploader_path
  err_msg = 'As you are using LocalDir uploader,' +
    ' you need to specify `local_dir_uploader_path` in your config' +
    ' so the uploader knows where to upload'
  @local_dir_uploader_path ||= config_yml.fetch('local_dir_uploader_path') { raise err_msg }
  pathnamed(@local_dir_uploader_path)
end

#log_levelObject



20
21
22
# File 'lib/bubbles/config.rb', line 20

def log_level
  @log_level || config_yml['log_level'] || 0
end

#log_pathObject



16
17
18
# File 'lib/bubbles/config.rb', line 16

def log_path
  @log_path || config_yml['log_path'] || STDOUT
end

#loggerObject



24
25
26
# File 'lib/bubbles/config.rb', line 24

def logger
  @logger ||= Logger.new(log_path).tap { |l| l.level = log_level }
end

#num_of_files_to_scheduleObject

how many files should DirWatcher schedule for upload, defaults to 1



68
69
70
# File 'lib/bubbles/config.rb', line 68

def num_of_files_to_schedule
  @num_of_files_to_schedule || 1
end

#processing_dirObject



33
34
35
36
# File 'lib/bubbles/config.rb', line 33

def processing_dir
  @processing_dir ||= config_yml.fetch('processing_dir') { raise_config_required }
  pathnamed(@processing_dir)
end

#s3_access_key_id=(value) ⇒ Object

Sets the attribute s3_access_key_id

Parameters:

  • value

    the value to set the attribute s3_access_key_id to.



11
12
13
# File 'lib/bubbles/config.rb', line 11

def s3_access_key_id=(value)
  @s3_access_key_id = value
end

#s3_bucketObject



109
110
111
112
113
# File 'lib/bubbles/config.rb', line 109

def s3_bucket
  @s3_bucket \
    || config_yml['s3_bucket'] \
    || raise('Please provide s3_bucket in your config file')
end

#s3_pathObject



97
98
99
100
101
# File 'lib/bubbles/config.rb', line 97

def s3_path
  @s3_path \
    || config_yml['s3_path'] \
    || ''
end

#s3_regionObject



91
92
93
94
95
# File 'lib/bubbles/config.rb', line 91

def s3_region
  @s3_region \
    || config_yml['s3_region'] \
    || raise('Please provide s3_region in your config file')
end

#s3_secret_access_key=(value) ⇒ Object

Sets the attribute s3_secret_access_key

Parameters:

  • value

    the value to set the attribute s3_secret_access_key to.



11
12
13
# File 'lib/bubbles/config.rb', line 11

def s3_secret_access_key=(value)
  @s3_secret_access_key = value
end

#sleep_intervalObject

number of seconds between every command execution in queue seconds, defaults to 1



61
62
63
64
65
# File 'lib/bubbles/config.rb', line 61

def sleep_interval
  @sleep_interval \
    || config_yml['sleep_interval'] \
    || 1
end

#source_dirObject



28
29
30
31
# File 'lib/bubbles/config.rb', line 28

def source_dir
  @source_dir ||= config_yml.fetch('source_dir') { raise_config_required }
  pathnamed(@source_dir)
end

#uniq_filename_randomizerObject



83
84
85
# File 'lib/bubbles/config.rb', line 83

def uniq_filename_randomizer
  @uniq_filename_randomizer ||= ->() { SecureRandom.uuid }
end

#uploader_classesObject



38
39
40
41
42
43
44
45
# File 'lib/bubbles/config.rb', line 38

def uploader_classes
  return @uploader_classes if @uploader_classes
  if uploaders = config_yml['uploaders']
    uploaders.map { |u| Object.const_get(u) }
  else
    [Bubbles::Uploaders::S3]
  end
end

#use_default_config_locations=(value) ⇒ Object

Sets the attribute use_default_config_locations

Parameters:

  • value

    the value to set the attribute use_default_config_locations to.



11
12
13
# File 'lib/bubbles/config.rb', line 11

def use_default_config_locations=(value)
  @use_default_config_locations = value
end

Class Method Details

.home_configObject



3
4
5
# File 'lib/bubbles/config.rb', line 3

def self.home_config
  Pathname.new(Dir.home).join('.bubbles/config.yml').to_s
end

.var_configObject



7
8
9
# File 'lib/bubbles/config.rb', line 7

def self.var_config
  '/var/lib/bubbles/config.yml'
end

Instance Method Details

#s3_aclObject



103
104
105
106
107
# File 'lib/bubbles/config.rb', line 103

def s3_acl
  @s3_acl \
    || config_yml['s3_acl'] \
    || 'private'
end

#s3_credentialsObject



87
88
89
# File 'lib/bubbles/config.rb', line 87

def s3_credentials
  @aws_credentials ||= Aws::Credentials.new(s3_access_key_id, s3_secret_access_key)
end