class EnvSync::Syncer::EnvSetting

Attributes

content[R]
env_file_name[R]
target_dir[R]

Public Class Methods

new(opts) click to toggle source
# 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

Public Instance Methods

target_env_path() click to toggle source
# File lib/env_sync.rb, line 20
def target_env_path
  Pathname.new(target_dir).join(env_file_name)
end
write!() click to toggle source
# File lib/env_sync.rb, line 24
def write!
  File.open(target_env_path, "w") do |file|
    file.puts content
  end
end

Private Instance Methods

validate!() click to toggle source
# File lib/env_sync.rb, line 32
def validate!
  raise InvalidFormat, "target_dir is not exists" unless File.exist?(target_dir)
  raise InvalidFormat, "target_dir is not a directory" unless File.directory?(target_dir)
end