module BuildpackChef
  class EnvDsl < BaseDsl

    def value(value)
      set_environment_variable(@name, value)
    end

    private

    def set_environment_variable(key, value)
      BuildpackChef::Builder.instance.add_to_profile_commands("export #{key}=#{value}")

      env_regex = /\$(.*)/
      if match = value.match(env_regex)
        match_key = match.captures.first
        new_value = value.gsub(env_regex, ENV[match_key])

        ENV[key] = new_value
      else
        ENV[key] = value
      end
    end

  end
end
