Class: YleTf::VarsFile
- Inherits:
-
Object
- Object
- YleTf::VarsFile
- Defined in:
- lib/yle_tf/vars_file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.find_env_vars_file(config) ⇒ Object
Returns the env specific tfvars file path if it exists.
-
.list_all_envs(config) ⇒ Object
Returns all envs that have tfvars files.
Instance Method Summary collapse
- #append_file(vars_file) ⇒ Object
- #append_vars(vars) ⇒ Object
-
#initialize(path) ⇒ VarsFile
constructor
A new instance of VarsFile.
- #read ⇒ Object
Constructor Details
#initialize(path) ⇒ VarsFile
Returns a new instance of VarsFile.
18 19 20 |
# File 'lib/yle_tf/vars_file.rb', line 18 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
16 17 18 |
# File 'lib/yle_tf/vars_file.rb', line 16 def path @path end |
Class Method Details
.find_env_vars_file(config) ⇒ Object
Returns the env specific tfvars file path if it exists
4 5 6 7 |
# File 'lib/yle_tf/vars_file.rb', line 4 def self.find_env_vars_file(config) path = "#{config.module_dir}/envs/#{config.tf_env}.tfvars" VarsFile.new(path) if File.exist?(path) end |
.list_all_envs(config) ⇒ Object
Returns all envs that have tfvars files
10 11 12 13 14 |
# File 'lib/yle_tf/vars_file.rb', line 10 def self.list_all_envs(config) Dir.glob("#{config.module_dir}/envs/*.tfvars").map do |path| File.basename(path, '.tfvars') end end |
Instance Method Details
#append_file(vars_file) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/yle_tf/vars_file.rb', line 26 def append_file(vars_file) File.open(path, 'a') do |file| file.puts # ensure we don't append to an existing line file.puts(vars_file.read) end end |
#append_vars(vars) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/yle_tf/vars_file.rb', line 33 def append_vars(vars) File.open(path, 'a') do |file| file.puts # ensure we don't append to an existing line vars.each do |key, value| file.puts %(#{key} = "#{value}") end end end |
#read ⇒ Object
22 23 24 |
# File 'lib/yle_tf/vars_file.rb', line 22 def read IO.read(path) end |