Class: EnvSync::Syncer::EnvSetting

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject (readonly)

Returns the value of attribute content.



10
11
12
# File 'lib/env_sync.rb', line 10

def content
  @content
end

#env_file_nameObject (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_dirObject (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_pathObject



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