class EnvSync::Syncer

Public Class Methods

new(options={}) click to toggle source
# File lib/env_sync.rb, line 38
def initialize(options={})
  @basic_envfile = (options || {}).fetch(:basic_envfile) { 'env.yaml' }
  @envs = parse_env_file!(File.read(@basic_envfile))
end

Public Instance Methods

sync!() click to toggle source
# File lib/env_sync.rb, line 43
def sync!
  @envs.each do |env|
    fullpath = env.target_env_path
    if File.exist?(fullpath)
      puts "** Overwrite #{fullpath}"
      puts "Before"
      puts File.read(fullpath)
      puts "---"
    else
      puts "** Write #{fullpath}"
    end

    env.write!
    puts File.read(fullpath)
    puts "Done."
  end
end

Private Instance Methods

parse_env_file!(str) click to toggle source
# File lib/env_sync.rb, line 63
def parse_env_file!(str)
  yaml = YAML.load(str)
  raise InvalidFormat unless yaml.is_a? Array

  yaml.map { |hash| EnvSetting.new(hash) }
end