Class: EnvSync::Syncer::EnvSetting
- Inherits:
-
Object
- Object
- EnvSync::Syncer::EnvSetting
- Defined in:
- lib/env_sync.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#env_file_name ⇒ Object
readonly
Returns the value of attribute env_file_name.
-
#target_dir ⇒ Object
readonly
Returns the value of attribute target_dir.
Instance Method Summary collapse
-
#initialize(opts) ⇒ EnvSetting
constructor
A new instance of EnvSetting.
- #target_env_path ⇒ Object
- #write! ⇒ Object
Constructor Details
#initialize(opts) ⇒ EnvSetting
Returns a new instance of EnvSetting.
12 13 14 15 16 17 18 |
# File 'lib/env_sync.rb', line 12 def initialize(opts) @target_dir = opts['dir'] || raise(InvalidFormat, "missing target dir") @content = opts['content'] || raise(InvalidFormat, "missing content") @env_file_name = opts.fetch('file') { '.env' } validate! end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
10 11 12 |
# File 'lib/env_sync.rb', line 10 def content @content end |
#env_file_name ⇒ Object (readonly)
Returns the value of attribute env_file_name.
10 11 12 |
# File 'lib/env_sync.rb', line 10 def env_file_name @env_file_name end |
#target_dir ⇒ Object (readonly)
Returns the value of attribute target_dir.
10 11 12 |
# File 'lib/env_sync.rb', line 10 def target_dir @target_dir end |
Instance Method Details
#target_env_path ⇒ Object
20 21 22 |
# File 'lib/env_sync.rb', line 20 def target_env_path Pathname.new(target_dir).join(env_file_name) end |
#write! ⇒ Object
24 25 26 27 28 |
# File 'lib/env_sync.rb', line 24 def write! File.open(target_env_path, "w") do |file| file.puts content end end |